excel-vba

how to bulk insert 255 columns from excel to SQL using VBA

安稳与你 提交于 2020-01-17 05:28:53
问题 I have to bulk insert from Excel to SQL using VBA I have written a function for that, but it is not working due to string max length. Can anyone help? below is the code I have written: Dim cn As Object: Set cn = CreateObject("ADODB.Connection") Dim ProjectName, SourceType As String ProjectName = ThisWorkbook.Sheets("Doorset Schedule").Range("B8") SourceType = "Production Schedule" ''You should probably change Activeworkbook.Fullname to the ''name of your workbook strCon = "Provider=Microsoft

VBA code works in debug mode but fails to run in whole

走远了吗. 提交于 2020-01-17 05:15:30
问题 Sub Export_as_PDF() Dim fil As Variant Dim strfile As String Dim PPApp As PowerPoint.Application Dim PPSlide As PowerPoint.Slide Dim SlideCount As Long Dim ws As Worksheet Dim Wb As Workbook Set PPApp = New PowerPoint.Application PPApp.Presentations.Add ' Slide 1 PPApp.ActivePresentation.Slides.Add PPApp.ActivePresentation.Slides.Count + 1,ppLayoutBlank Set PPSlide = PPApp.ActivePresentation.Slides (PPApp.ActivePresentation.Slides.Count) PPApp.ActiveWindow.View.GotoSlide PPApp

Display Row Values based on Nearest Numeric Match of Key

跟風遠走 提交于 2020-01-17 05:14:05
问题 Say I have a sorted list of values in column A. They serve as a 'key' to each numerical row. Something like this: ___A_(key)_______B______ ______G_____ 1 |____2.58___|____________| ... |____________| ... 2 |____2.69___|____________| ... |____________| ... ... ... ... ________________________ ____________ x |____5.69___|____________| ... |____________| ... Columns B through G have some values for each of the keys, so it's basically a 2D spreadsheet of numerical data. I need to be able to

(VBA) Excel with thousands of rows - how to transpose variable length columns to rows?

↘锁芯ラ 提交于 2020-01-17 04:44:27
问题 I have an Excel sheet I am working with 9948 rows. A cell would have multiple pieces of information contained within it so what I've done so far is delimit those through Excel's text-to-column feature. (All data and column headers are arbitrary) It started out like this: ID | Name | Property1 | 1 Apple JO18, GFBAJH, HFDH, 78EA It has data (in mixed text/number format) in the first couple columns that should actually be on their own row. The amount of properties one of these have varies so one

Last Row Paste to different Worksheet VBA

只谈情不闲聊 提交于 2020-01-17 04:44:08
问题 I am trying to paste info on the last row of a different worksheet. I already have the info copied and this macro is just to paste it. With the code that I have now, I am getting an error that says "Paste Method of Worksheet Class Failed" how can I fix this? here is the code: Windows("m.xlsx").Activate Cells(Application.Rows.Count, 1).End(xlUp).Offset(1, 0).Select ActiveSheet.Paste Range("D45").Select Windows("d.xlsx").Activate 回答1: Excel is known to clear the clipboard and hence you should

Create a new workbook, import Macro and assign button

こ雲淡風輕ζ 提交于 2020-01-17 04:40:09
问题 I've created some VBA code to create new workbook, spawn some worksheet elements and import a code module. Then I want to link the button to the macros in the newly created file using those imported modules. Instead VBA is trying to assign the button of the newly created file to the macros in the workbook running the code, rather than the destination file itself. I'm using a line: destwb.Worksheets(newSheetName).Shapes("Button 1").OnAction = "Test_Button_Press" Where destwb is the new

Filtering between two dates in excel vba

不打扰是莪最后的温柔 提交于 2020-01-17 04:38:26
问题 I need help to filter between two dates and it's giving me an error: Named argument not found my code Dim StartDate As String Dim EndDate As String ' StartDate = Date EndDate = Date + 365 ' ActiveSheet.AutoFilter Field:=7, Criteria1:=">=StartDate", Operator:=xlAnd, Criteria2:="<=EndDate" Any help would be much appreciated! 回答1: if your dates are actual Date values (i.e. not String ones looking like dates), then go like this: Dim StartDate As Date Dim EndDate As Date StartDate = Date EndDate =

Select column in a selected range VBA

安稳与你 提交于 2020-01-17 04:32:04
问题 I'm trying to filter my table and copy just a column in my filtered range at a time. I tried to get column 2 in my range but it returns only the first cell. I also tried .entireColumn, but it returns the entireColumn, not the selected entire column. Sub FillStocks(ByVal myDate As Date, ByVal name As String) strDate = Format(myDate, "dd/MM/yyyy") 'Filter With Sheets("BD_Sheet") Set tableRange = .UsedRange With tableRange Call .AutoFilter(1, strDate) Call .AutoFilter(2, name) End With On Error

On row insertion autopopulate a formula in a cell

半世苍凉 提交于 2020-01-17 04:22:04
问题 I have a formula column in my spreadsheet to calculate values based on another column. I want to know if there is a way to make the formula default so that when I insert a new row, the cell of that column automatically gets the formula pre-set, no need to copy and paste from above again. This is desirable because the spreadsheet will be filled in by non-technical users. The current workaround is to pre-copy-&-paste the whole column with the formula but this is not ideal as the file becomes

Multi-row and multi-column excel spreadsheet into single column keeping column A as key

前提是你 提交于 2020-01-17 04:19:06
问题 Consider a table: a b c d key1 value1 value2 value3 key2 value1a value3a i need to convert this into Key1 Value1 Key1 Value2 Key1 Value3 Key2 Value1a Key2 key2 Value3a this code, works in putting all the data into a single column, including spaces as required, but i need to keep the first column as a key and I'm new to VBA in excel. Sub MultiColsToA() Dim rCell As Range Dim lRows As Long Dim lCols As Long Dim lCol As Long Dim ws As Worksheet Dim wsNew As Worksheet lCols = Columns.Count lRows