Hello wonderful Excel gurus,
I have a bit of VBA code I could use help with. It's fairly straight-forward. Based on two cells, tt looks up a value in another workbook, copies it, closes that workbook, and pastes the value where I want it. However, I'm getting a 1004 error.
Here's the code:
Sub copytimezone()
Dim client As String
Dim Domain As String
client = Worksheets("Dashboard").Range("$BV$1").Value
Domain = Worksheets("Dashboard").Range("$BV$2").Value
Worksheets("Dashboard").Activate
Worksheets("Dashboard").Range("BW2").Clear
Workbooks.Open Filename:="XXXXXXX"& client & "&Domain=" & Domain & "&rs:Format=CSV"
' Select the range to copy from the csv
Range("A2").Select
Selection.Copy
'Selection.ClearContents
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=False
' Note:- Name of this file should be same as the file name.
Worksheets("Dashboard").Activate
'Copy csv data into this spread sheet at this Range
Application.ScreenUpdating = True
Worksheets("Dashboard").Range("BW2").Select
Worksheets("Dashboard").Range("BW2").PasteSpecial
The line is red is where the debugger points. After reading other threads, here's what I've tried so far:
- Putting a pause before the PasteSpecial
- Using just Paste instead of "PasteSpecial"
- Using Active Worksheet instead of specifying the worksheet
None of this has helped. Any help you can give would be glorious.
Cheers!
I have a bit of VBA code I could use help with. It's fairly straight-forward. Based on two cells, tt looks up a value in another workbook, copies it, closes that workbook, and pastes the value where I want it. However, I'm getting a 1004 error.
Here's the code:
Sub copytimezone()
Dim client As String
Dim Domain As String
client = Worksheets("Dashboard").Range("$BV$1").Value
Domain = Worksheets("Dashboard").Range("$BV$2").Value
Worksheets("Dashboard").Activate
Worksheets("Dashboard").Range("BW2").Clear
Workbooks.Open Filename:="XXXXXXX"& client & "&Domain=" & Domain & "&rs:Format=CSV"
' Select the range to copy from the csv
Range("A2").Select
Selection.Copy
'Selection.ClearContents
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=False
' Note:- Name of this file should be same as the file name.
Worksheets("Dashboard").Activate
'Copy csv data into this spread sheet at this Range
Application.ScreenUpdating = True
Worksheets("Dashboard").Range("BW2").Select
Worksheets("Dashboard").Range("BW2").PasteSpecial
The line is red is where the debugger points. After reading other threads, here's what I've tried so far:
- Putting a pause before the PasteSpecial
- Using just Paste instead of "PasteSpecial"
- Using Active Worksheet instead of specifying the worksheet
None of this has helped. Any help you can give would be glorious.
Cheers!