Write to a variable cell location

GrantG3SA

New Member
Joined
Dec 23, 2019
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi,

Can someone advise me how to find the Column location from my first match so that I can make the range variable. My code below successfully finds the store in range C3 to H3. I want to know if its column E, then my range in bold when I copy must be E6 to E58. I cannot find how to make that range vary on the column number.

Sub SAVE()
Dim Store As String

'Set Store to Cell C2 from worksheet Entry
Store = Range("C2").Value
'Look for Store in Worksheet Orders to obtain range to copy to
If Not IsError(Application.Match(Store, Sheets("Orders").Range("C3:H3"), 0)) Then
'The value found in the given range
'Copy C3:C55 from Entry worksheet into found Range from Orders Worksheet
Worksheets("Orders").Range("C6:C58").Value = Worksheets("Entry").Range("C3:C55").Value


End If

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Assuming the C2 cell is on the "Entry" sheet, try
VBA Code:
Sub GrantG3SA()
    Dim Fnd As Range
    With Sheets("Entry")
        Set Fnd = Sheets("Orders").Range("C3:H3").Find(.Range("C2").Value, , , xlWhole, , , False, , False)
        If Not Fnd Is Nothing Then
            Fnd.Offset(3).Resize(53).Value = .Range("C3:C55").Value
        End If
    End With
End Sub
 
Upvote 0
Assuming the C2 cell is on the "Entry" sheet, try
VBA Code:
Sub GrantG3SA()
    Dim Fnd As Range
    With Sheets("Entry")
        Set Fnd = Sheets("Orders").Range("C3:H3").Find(.Range("C2").Value, , , xlWhole, , , False, , False)
        If Not Fnd Is Nothing Then
            Fnd.Offset(3).Resize(53).Value = .Range("C3:C55").Value
        End If
    End With
End Sub
Thanks Fluff. Works perfectly!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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