ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using VBA to Copy Ranges to a PreSet Dim formula AND Cell Propertys. (https://www.excelbanter.com/excel-programming/446774-using-vba-copy-ranges-preset-dim-formula-cell-propertys.html)

omen666blue

Using VBA to Copy Ranges to a PreSet Dim formula AND Cell Propertys.
 
Hi all, Im working on a Rotseirn form were i allow the user to build there own roster Just by inserting a number into a Cell and clicking a button. Iv got most of the way But just need the last few Bits.

Basically i Use Dim Sets at the start of my Macro that copy a template range and Then runs a loop depending on what the user has input into the cell next to the button. I Have a Auto Fit command at the end of the Loop that fixes one of my problems But what i would Like is for the Macro to copy All the Cell Setting I.e Column Width+Height And Borders. and then to paste these in the Loop.

What iv got so far is this:
================================================== =====
Sub Ne()
Dim E As Variant
Dim Name As Variant
Dim Count As Integer
Dim lastRow As Long
Count = 0
Count2 = 3

E = Worksheets("Template").Range("$B$3:$AD$3").Formula
Name = Worksheets("Sheet1").Range("$C$3")
Sheets.Add.Name = Name

Do Until Count = Worksheets("Sheet1").Range("$C$4")
If Count = 1000 Then Exit Do
Count = Count + 1
Count2 = Count2 + 1
Worksheets(Name).Cells(Count2, "A") = Count
Worksheets(Name).Cells(Count2, "AE") = Count
Worksheets(Name).Range(Cells(Count2, "B"), Cells(Count2, "AD")) = E

Loop

Worksheets(Name).Range("A:AE").Columns.AutoFit

MsgBox ("The loop ran " & Count & " times.")

End Sub
================================================== =======

Any Help Would Be much Appreciated.
I Have tried Adding Another Dim As so and Making its Value As Below
W = Worksheets("Template").Range("$B$3:$AD$3").Borders ().LineStyle
Then Making the Cells W, To No Avail.

Thanks for taking the time to look!

Regards
chris


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com