I have an input sheet, and 13 report sheets.
The input sheet is a must for internal data.
I am trying to write vba code for a button to copy four columns on input sheet.
The problem is that there will be a different "paste to" column reference for each sheet.
I have all of the column references on the input sheet.
I cannot figure out how to loop copy the columns (maintaining widths) while using the changing column references.
I found basic loop code and paste column code, but need help to assign variables. I am very weak using the Cells reference.
I appreciate any advice.
I just need a starting point...
copy columns to multiple sheets with different column references
- Ken Santopietro
- Thread is marked as Resolved.
-
-
Re: copy columns to multiple sheets with different column references
Why not post the code you have so we can see where you've got to? If you want to attach a sample file, that always helps.
-
Re: copy columns to multiple sheets with different column references
OK
-
Re: copy columns to multiple sheets with different column references
This should start you off, but will probably need adjusting for actual file. You need to have a table containing sheet names (and nothing else) and column letters.
Code
Display MoreSub x() Dim r As Long, rSheets As Range, rData As Range With Sheets("input") Set rSheets = .Range("B24").CurrentRegion Set rData = .Range("A3", .Range("D20").End(xlUp)) For r = 1 To rSheets.Rows.Count rData.Copy Sheets(CStr(rSheets(r, 1))).Cells(1, CStr(rSheets(r, 3))).PasteSpecial xlValues Sheets(CStr(rSheets(r, 1))).Cells(1, CStr(rSheets(r, 3))).PasteSpecial xlPasteColumnWidths Next r End With End Sub
-
Re: copy columns to multiple sheets with different column references
Fantastic start.. thank you.
-
-
Re: copy columns to multiple sheets with different column references
Here is the current problem. I named ranges (a dynamic range for the copy selection range), along with a range name for the table with the references to copy to... error perplexes me.
-
Re: copy columns to multiple sheets with different column references
When it errors, hover over the yellow line and the current values of the various elements of that line should appear so hopefully error will become apparent. Otherwise attach a file with revised layout.
-
Re: copy columns to multiple sheets with different column references
just found that out, fixed references and it is working but not copying range I need.
I have a cell where I have user fill in start column and end column... for example, PA column to start and PW column to end.
In another cell, hidden in white, my formula is =cell&1... resulting in a text cell reference.
I don't know how to call for the cell reference represented by this text..
here is what I found and tried without success - VBA works but copies the cell reference and some surrounding cells only (kind of funny to see)
I used this line:Set rData = .Range(([indirect("e28")]), .Range([indirect("e29")]))
e28 contains the characters PA3,
e29 contains the characters PW18Thanks for looking at this!
Ken -
Re: copy columns to multiple sheets with different column references
Forgot to mention... the column reference the user chooses will change every day.
for this example I want the copy range to become the same as: Set rData = .Range("PA3", .Range("PW18")) -
-
-
Re: copy columns to multiple sheets with different column references
WORKS NOW! Thanks so much for your assistance. Ken
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!