Simpify this code

s45yth

New Member
Joined
Jun 7, 2011
Messages
6
Basically i am copying a name from cell C4, copying it and pasting it into Cell F4.........

Then if there is a name in Cell C5, Copy it and paste into Cell F4 again...

Then if there is a name in Cell C6, Copy it and paste it into Cell F4 again...

Then if there is no name in Cell C7, stop....

But at a later date, if a name is input into C7, C8, C9 etc.. copy these names into F4 again....

what is happening is when the name is input into Cell F4.... a data table is generated, which is then copied to a new sheet...

Please find a simplified version of this workbook attached and the macro i recorded (upto 5 rows) below..

Any help will be much appreciated....

Thanks

Scotty

Sub Macro1()
'
' Macro1 Macro
'

'
Range("C4").Select
Selection.Copy
Range("F4").Select
ActiveSheet.Paste
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Fees").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "I500001"
Sheets("Fees").Select
Range("H4:L46").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("I500001").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Fees").Select
Range("C5").Select
Application.CutCopyMode = False
Selection.Copy
Range("F4").Select
ActiveSheet.Paste
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Fees").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "I500002"
Sheets("Fees").Select
Range("H4:L46").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("I500002").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Fees").Select
Range("C6").Select
Application.CutCopyMode = False
Selection.Copy
Range("F4").Select
ActiveSheet.Paste
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Fees").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "I500003"
Sheets("Fees").Select
Range("H4:L46").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("I500003").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Fees").Select
Range("C7").Select
Application.CutCopyMode = False
Selection.Copy
Range("F4").Select
ActiveSheet.Paste
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Fees").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "I500004"
Sheets("Fees").Select
Range("H4:L46").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("I500004").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Fees").Select
Range("C8").Select
Application.CutCopyMode = False
Selection.Copy
Range("F4").Select
ActiveSheet.Paste
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Fees").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet5").Select
Sheets("Sheet5").Name = "I500005"
Sheets("Fees").Select
Range("H4:L46").Select
Sheets("Fees").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("I500005").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub
<!-- / message --><!-- attachments -->
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
To give you first help: to copy a value from 1 cell to another, use:

Code:
Range("F4").Value = Range("C4").Value

instead of:

Code:
Range("C4").Select
Selection.Copy
Range("F4").Select
ActiveSheet.Paste

This will already simplify it.

Take out all Select's and Activate's.

Look at other posts in the Board for a loop; you need to test how far the data stretch, and stop at the correct cell.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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