VBA InputBox that allows user to search for a column header name, then sopy range to another workbook

Status
Not open for further replies.

Palucci

Banned user
Joined
Sep 15, 2021
Messages
138
Office Version
  1. 365
Platform
  1. Windows
Hello All :)
I write a macro that will open files with inputbox to search header for date. When it finds date, it will copy the range lines 101: 119 and paste them into ThisWorkbook at the Range of my choice. However, I ran into a problem right from the start in the headers search. I got error :

Run-time error '1004' - Method 'Range' of object'_Global' failed

Rich (BB code):
Sub Macro10()


Dim data_wb As Workbook
Dim target_wb As Workbook
Dim file_name As Variant
Dim header_range(100) As Range
Dim x As Variant
Dim Col As Long

'Open file
file_name = Application.GetOpenFilename(Title:="Choose a target Workbook")

If file_name <> False Then

    'Setworkbook
    Set target_wb = ThisWorkbook

    'Set data file
    Set data_wb = Application.Workbooks.Open(file_name)
    
    'Input box
x = InputBox("Please probide Data YYYY/MM/DD")


target_wb.Close
End If
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Any guys can help ? I have some inputBox but its not selected any poistion on data_wb
Rich (BB code):
Do
        inputbx = InputBox("Enter Date, FORMAT; YYY-MM-DD", , Format(VBA.Now, "YYYY-MM-DD"))
        If inputbx = vbNullString Then Exit Sub
        inputstr = Split(inputbx, "-")
        On Error Resume Next
        InputDate = DateSerial(inputstr(2), inputstr(0), inputstr(1))
        On Error GoTo 0
        DateIsValid = IsDate(InputDate)
        If Not DateIsValid Then MsgBox "Please enter a valid date.", vbExclamation
    Loop Until DateIsValid
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top