VBA/Macro Help. Hopefully easy but I have NO idea what I am doing.

ned lud

New Member
Joined
Jan 30, 2024
Messages
15
Office Version
  1. 2019
Below are the macros I have.

Macro 1 simply takes a table on the "frontpage" tab at (A21:E73) and sorts it by the E column values. Works perfectly.

Macro 3 takes the values in cells A17:AF17 on the "frontpage" tab and copies them into the "sheet 3" tab in the next blank row. Also works perfectly.

The problem I am having is that Marco 3 does not quite work. I get #REF! in every pasted cell instead of the values that were in A17>AF17.

Here is what I am hoping you can help me with:

1) I want the the copy/pasting to work so the values are shown on page three.

2) I'd like to combine both macros so, when I assign it to a button, both step happen at the same time.

Thank you very much for any help you can provide. I assume this is easy but I know nothing about VBA.

------------------------------------------

Sub macro1()
'
' macro1 Macro
'
' Keyboard Shortcut: Ctrl+a
'
ActiveWindow.SmallScroll Down:=18
Range("A21:E73").Select
ActiveWorkbook.Worksheets("Front Page").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Front Page").Sort.SortFields.Add2 Key:=Range( _
"E22:E73"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Front Page").Sort
.SetRange Range("A21:E73")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=-18
Range("E2").Select
End Sub
Sub Macro3()
'
' Macro3 Macro
'
' Keyboard Shortcut: Ctrl+s
'

Range("A17:af17").Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

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.
sounds like the ranges are different but you could try this instead of copy paste:
VBA Code:
Dim LR as Long
LR = Sheets("Sheet3").Cells(Rows.count, "A").End(xlUp).Row +1
Sheets("Sheet3").Range("A" & LR & ":AF" & LR).value = Range("A17:af17").Value
See if that works for you.
 
Upvote 0
Solution
Try. Change this
VBA Code:
Range("A17:af17").Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
as
VBA Code:
Range("A17:af17").Copy
 Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
sounds like the ranges are different but you could try this instead of copy paste:
VBA Code:
Dim LR as Long
LR = Sheets("Sheet3").Cells(Rows.count, "A").End(xlUp).Row +1
Sheets("Sheet3").Range("A" & LR & ":AF" & LR).value = Range("A17:af17").Value
See if that works for you.
This works. Thank you very much.
 
Upvote 0
Try. Change this
VBA Code:
Range("A17:af17").Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
as
VBA Code:
Range("A17:af17").Copy
 Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
This works as well. Thank you very much.
 
Upvote 1

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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