VBA help

mssbass

Active Member
Joined
Nov 14, 2002
Messages
253
Platform
  1. Windows
I've got a row (Q1:BH1)with mutually exclusive dates. My 2nd row has formulas (Q2:BH2) that pull in related data.
I've also got 1 cell with a specific date (Q13)

If a date on my first row matches to the date in cell Q13, I want to copy/paste special values in the 2nd row in the cell below the matching date in order to get rid of the formula.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Public Sub CopyMatchingValue()

Dim foundColumn As Variant

foundColumn = Evaluate("MATCH(Q13,Q1:BH1,0)")
If Not IsError(foundColumn) Then
    With Range("Q2:BH2")(foundColumn)
        .Value = .Value
    End With
End If

End Sub

WBD
 
Upvote 0
Worked great - now I have multiple with statements - how to I clean this up?

Sub B_Finalize()
Dim WKS As Worksheet
Set WKS = ThisWorkbook.Worksheets("3_Vol 295")
Set WKS2 = ThisWorkbook.Worksheets("3_Vol 520")
Set WKS3 = ThisWorkbook.Worksheets("3_Vol 524")
Dim foundColumn As Variant
foundColumn = Evaluate("MATCH(Q13,Q1:BH1,0)")
If Not IsError(foundColumn) Then
With WKS.Range("Q2:BH2")(foundColumn)
.Value = .Value
With WKS.Range("Q3:BH3")(foundColumn)
.Value = .Value
With WKS.Range("Q4:BH4")(foundColumn)
.Value = .Value
With WKS2.Range("Q2:BH2")(foundColumn)
.Value = .Value
With WKS2.Range("Q3:BH3")(foundColumn)
.Value = .Value
With WKS2.Range("Q4:BH4")(foundColumn)
.Value = .Value
With WKS3.Range("Q2:BH2")(foundColumn)
.Value = .Value
With WKS3.Range("Q3:BH3")(foundColumn)
.Value = .Value
With WKS3.Range("Q4:BH4")(foundColumn)
.Value = .Value
End With
End With
End With
End With
End With
End With
End With
End With
End With
End If
End Sub
 
Upvote 0
Code:
Sub B_Finalize()

Dim sheetArray
Dim thisRow As Long
Dim thisSheet As Long
Dim foundColumn

sheetArray = Array("3_Vol 295", "3_Vol 520", "3_Vol 524")
foundColumn = Evaluate("MATCH(Q13,Q1:BH1,0)")

If IsError(foundColumn) Then Exit Sub

For thisSheet = LBound(sheetArray) To UBound(sheetArray)
    For thisRow = 2 To 4
        With Sheets(sheetArray(thisSheet)).Range("Q" & thisRow & ":BH" & thisRow)(foundColumn)
            .Value = .Value
        End With
    Next thisRow
Next thisSheet

End Sub

Untested.

WBD
 
Upvote 0

Forum statistics

Threads
1,215,620
Messages
6,125,876
Members
449,268
Latest member
sGraham24

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