Macro needs adjusting for active cell

rlcurlee67

New Member
Joined
Jun 1, 2022
Messages
11
Office Version
  1. 2013
Platform
  1. Windows
What I want my macro to do is where ever my cursor is on the sheet is my active cell.
Then goto the X:\...... path
and copy what is in cell B46
Then go back to my active sheet and active cell and paste.

It is not doing that.
Can you assist.


[Sub Macro10()
'
' Macro10 Macro
'

'
Dim myFile As String
Dim YourFolderPath As Variant

Sheets("2022 Oil Production").Select
YourFolderPath = "X:\UTCS\Region\USA\Assets\GOM_DEV\Julia\SubSrfc\Rsvr_Mgmt-Surv\Surv-Data\Prod\St. Malo Morning Report - by Prod Date\2022"
ChDir YourFolderPath
ChDrive "X"
myFile = Application.GetOpenFilename
Range("B46").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Project 3. Oil Production copy (003).xlsx").Activate
Sheets("2022 Oil Production").Select
ActiveCell.Paste
End Sub]
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
try this modification to save the active cell in a range object:
VBA Code:
Sub Macro10()

'
' Macro10 Macro
'

'
Dim myFile As String
Dim YourFolderPath As Variant
Dim rng As Range
Set rng = Range(ActiveCell, ActiveCell)

Sheets("2022 Oil Production").Select
YourFolderPath = "X:\UTCS\Region\USA\Assets\GOM_DEV\Julia\SubSrfc\Rsvr_Mgmt-Surv\Surv-Data\Prod\St. Malo Morning Report - by Prod Date\2022"
ChDir YourFolderPath
ChDrive "X"
myFile = Application.GetOpenFilename
Range("B46").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Project 3. Oil Production copy (003).xlsx").Activate
Sheets("2022 Oil Production").Select
rng.Select
ActiveCell.Paste
End Sub
 
Upvote 0
I gives me an error at the last line Activecell.paste. Wouldn't I need to put the rng.select at the top to save that range?
 
Upvote 0
try this modification:
VBA Code:
Sub Macro10()

'
' Macro10 Macro
'

'
Dim myFile As String
Dim YourFolderPath As Variant
Dim rng As Range
Dim B46 As Variant
Set rng = Range(ActiveCell, ActiveCell)

Sheets("2022 Oil Production").Select
YourFolderPath = "X:\UTCS\Region\USA\Assets\GOM_DEV\Julia\SubSrfc\Rsvr_Mgmt-Surv\Surv-Data\Prod\St. Malo Morning Report - by Prod Date\2022"
ChDir YourFolderPath
ChDrive "X"
myFile = Application.GetOpenFilename
B46 = Range("B46")
Windows("Project 3. Oil Production copy (003).xlsx").Activate
Sheets("2022 Oil Production").Select
rng = B46
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,135
Messages
6,123,241
Members
449,093
Latest member
Vincent Khandagale

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