VBA to find Correct Column and Copy/Paste Values

moony

New Member
Joined
Jul 22, 2019
Messages
20
Hello,

I am working on a sheet called Monthly that automatically pulls the relevant data from the ABR Drop In sheet. The cells confirm the month referenced above in cell H5 matches the date inputted in the ABR Drop In sheet in cell H5. The Monthly sheet has the dates listed in Monthly!$F$5:$EH$5. Only the blue cells are inputs, and the goal is to have a button on the ABR Drop In sheet that will look at the date in cell 'ABR Drop In'!H5, find that column in the Monthly sheet, and copy/paste all the blue input cells as values.

Appreciate any help I can get!

Thanks!
Hotel AM Tracker v1 - test.xlsx
BCDEFGH
5Input Month Ending Date of Statements Below:12/31/2021
ABR Drop In
Hotel AM Tracker v1 - test.xlsx
H
5Dec 2021
62
71
8
949
10
11
12
131,519
14458
15351
16107
1730.2%
18990.66
191,240.21
20396.58
21298.70
22
23--
24--
25
26
27--
28--
29
30
31--
32
33--
34--
35
36
37--
38--
39
40
41--
42
431,519
44458
45351
46107
4730.2%
48990.66
49
50
51298.70
52
53
54453,721
55
56
57215,575
58116,669
598,941
6025,887
61971
6263,107
63103,983
6499,743
652,153
661,800
67287
68
6915,602
7012,600
71
7246,337
731
74--
7536,316
76424
779,596
78
79847,818
80
81
82242,656
83
84
85422,221
8628,207
87
88
8981,249
90--
91--
9273,960
937,289
940
95
96774,333
97
9873,485
99
100
101196,141
10244,272
103166,620
10466,466
10528,330
106
107501,830
108
109(428,345)
110
11121,195
112
113
114(449,540)
115
116
117(78,884)
11812,617
1195,070
120
121
122
123
124(61,197)
125
126(388,343)
127
12816,927
129
130(405,270)
Monthly
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
this is what i created by putting different things together. not sure if this is a good/efficient way, but it seems to work.
I created a dummy workbook to test it out.
VBA Code:
Sub PasteMonthlyPL()
 
 Dim rng As Range
 Dim MonthlyPL As String
 Dim colnumber As Long
 
 MonthlyPL = Sheet1.Cells(1, 1)

 Set rng = Sheet2.Rows("1:1").Find(What:=MonthlyPL, _
    LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    colnumber = rng.Columns
    Sheet2.Range(Cells(2, colnumber), Cells(4, colnumber)).Copy
    Sheet2.Range(Cells(2, colnumber), Cells(4, colnumber)).PasteSpecial Paste:=xlPasteValues
    Sheet2.Range(Cells(7, colnumber), Cells(9, colnumber)).Copy
    Sheet2.Range(Cells(7, colnumber), Cells(9, colnumber)).PasteSpecial Paste:=xlPasteValues
    Sheet2.Range(Cells(12, colnumber), Cells(14, colnumber)).Copy
    Sheet2.Range(Cells(12, colnumber), Cells(14, colnumber)).PasteSpecial Paste:=xlPasteValues
    Sheet2.Range(Cells(17, colnumber), Cells(18, colnumber)).Copy
    Sheet2.Range(Cells(17, colnumber), Cells(18, colnumber)).PasteSpecial Paste:=xlPasteValues
    Sheet2.Cells(20, colnumber).Copy
    Sheet2.Cells(20, colnumber).PasteSpecial Paste:=xlPasteValues
End Sub
 
Upvote 0
i copied it over and made the adjustments so it fit the workbook i need, but i'm getting an error at the colnumber = rng.Columns line:

VBA Code:
Sub PasteMonthlyPL()
 
 Application.ScreenUpdating = False
 Dim rng As Range
 Dim MonthlyPL As String
 Dim colnumber As Long
 
 MonthlyPL = ActiveWorkbook.Sheets("ABR Drop In").Cells(5, 8)
 Sheets("Monthly").Activate

 Set rng = ActiveSheet.Rows("5:5").Find(What:=MonthlyPL, _
    LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    colnumber = rng.Columns
    
    ActiveSheet.Cells(9, colnumber).Copy
    ActiveSheet.Cells(9, colnumber).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Cells(54, colnumber).Copy
    ActiveSheet.Cells(54, colnumber).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(58, colnumber), Cells(62, colnumber)).Copy
    ActiveSheet.Range(Cells(58, colnumber), Cells(62, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(64, colnumber), Cells(67, colnumber)).Copy
    ActiveSheet.Range(Cells(64, colnumber), Cells(67, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(69, colnumber), Cells(70, colnumber)).Copy
    ActiveSheet.Range(Cells(69, colnumber), Cells(70, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(73, colnumber), Cells(77, colnumber)).Copy
    ActiveSheet.Range(Cells(73, colnumber), Cells(77, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Cells(82, colnumber).Copy
    ActiveSheet.Cells(82, colnumber).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(90, colnumber), Cells(94, colnumber)).Copy
    ActiveSheet.Range(Cells(90, colnumber), Cells(94, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(101, colnumber), Cells(105, colnumber)).Copy
    ActiveSheet.Range(Cells(101, colnumber), Cells(105, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Cells(111, colnumber).Copy
    ActiveSheet.Cells(111, colnumber).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Range(Cells(117, colnumber), Cells(119, colnumber)).Copy
    ActiveSheet.Range(Cells(117, colnumber), Cells(119, colnumber)).PasteSpecial Paste:=xlPasteValues
    
    ActiveSheet.Cells(128, colnumber).Copy
    ActiveSheet.Cells(128, colnumber).PasteSpecial Paste:=xlPasteValues

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello,​
of course as this codeline has no sense ! (Just reading VBA help …) So what this codeline is supposed to do ?​
 
Upvote 0
According to your thread title a VBA demonstration to replace all formulas in a found column with their values for starters :​
VBA Code:
Sub Demo1()
    Dim V
    With Sheets("Monthly").UsedRange.Columns
        V = Application.Match(['ABR Drop In'!H5].Text, .Rows(5), 0)
        If IsNumeric(V) Then .Item(V).Formula = .Item(V).Value2
    End With
End Sub
 
Last edited:
Upvote 0
According to your thread title a VBA demonstration to replace all formulas in a found column with their values for starters :​
VBA Code:
Sub Demo1()
    Dim V
    With Sheets("Monthly").UsedRange.Columns
        V = Application.Match(['ABR Drop In'!H5].Text, .Rows(5), 0)
        If IsNumeric(V) Then .Item(V).Formula = .Item(V).Value2
    End With
End Sub
thanks for the response!
I'll give it a try and will let you know.

Much appreciated

Edit:
Will this replace all formulas in the column, because there are many rows that should not be replaced with values. In the example above, only the rows with the blue inputs need to be replaced with values
 
Upvote 0
is there another solution to this? the above proposed solution converts every formula into a value, which is not the intention. Only the designated blue input rows need to be pasted as values.

Thanks!
 
Upvote 0

So link your workbook on a files host website like Dropbox …​
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,593
Members
449,038
Latest member
Arbind kumar

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