Glasgowsmile
Active Member
- Joined
- Apr 14, 2018
- Messages
- 280
- Office Version
- 365
- Platform
- Windows
Good day,
I'm trying to come up with VBA code to import a few columns of data from an exported spreadsheet. The challenge is that the amount of columns and even the columns the data end up in are subject to change each time the report is pulled. There is 1 consistent factor though that I think I can use to pull the remaining data.
Each time the sheet is exported there is a header above the columns that are merged across all the columns I need to pull. "Rate Heading" is the header for that, so how would I write VBA to specifically find the Rate Heading section of the report and then pull all the data below that merged column?
Currently, this is what I'm working with which I pulled from another report I have that needed something similar but not as complex.
I'm trying to come up with VBA code to import a few columns of data from an exported spreadsheet. The challenge is that the amount of columns and even the columns the data end up in are subject to change each time the report is pulled. There is 1 consistent factor though that I think I can use to pull the remaining data.
Each time the sheet is exported there is a header above the columns that are merged across all the columns I need to pull. "Rate Heading" is the header for that, so how would I write VBA to specifically find the Rate Heading section of the report and then pull all the data below that merged column?
Currently, this is what I'm working with which I pulled from another report I have that needed something similar but not as complex.
VBA Code:
Sub DiscountPer()
Application.DisplayAlerts = False
Dim Fnd As Range
Dim Hrg As Range
Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "CSV Files", "*.csv"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Set wkbSourceBook = Workbooks.Open(.SelectedItems(1))
Set Fnd = Range("A1:AG1").Find("Rate Heading", , , xlPart, , , False, , False)
Range(Fnd.Offset(1), Range("N2000")).Copy
wkbCrntWorkBook.Sheets("RC1").Range("A1").PasteSpecial xlPasteValues
wkbCrntWorkBook.Sheets("RC1").Range("A1").Value = ActiveSheet.Range("B13").Value
wkbSourceBook.Close False
End If