Trying to simplify my macro code...

Zurina

New Member
Joined
Aug 21, 2013
Messages
9
Hi experts out there.
Help me plssss...

I need to simplify the codes below because i know if I still continue with these, the procedure are going to be large.

The problem is I just dun know how to put the cut, copy and paste things into formula.

Appreciate your help.
Thanks. Zurina

KL, Malaysia.





Sub UIC()
'
' UIC Macro
'
' Keyboard Shortcut: Ctrl+o


Select Case Sheets("Fs").Range("A9").Value

'A-MYR

Case 1
Sheets("UIC").Select
Range("C10:L10").Select
Selection.Copy
Range("C11").Select
ActiveSheet.Paste
Application.CutCopyMode = False

Range("C10:L10").Select
Selection.Copy
Range("C10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Case 2
Sheets("UIC").Select
Range("C11:L11").Select
Selection.Copy
Range("C12").Select
ActiveSheet.Paste
Application.CutCopyMode = False

Range("C11:L11").Select
Selection.Copy
Range("C11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Case 3
Sheets("UIC").Select
Range("C12:L12").Select
Selection.Copy
Range("C13").Select
ActiveSheet.Paste
Application.CutCopyMode = False

Range("C12:L12").Select
Selection.Copy
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,772
Based on your existing code, the below should work (note: untested)

Code:
Sub UIC()
Dim x As Long
Application.ScreenUpdating = False
x = Sheets("Fs").Range("A9")

With Sheets("UIC")
    With .Cells(9 + x, 3).Resize(1, 10)
        .Copy .Offset(1)
        .Formula = .Value
    End With
End With
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,648
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Change your cases to something like this
Code:
Case 1
Sheets("UIC").Range("C10:L10").Copy Destination:=Range("C11")
With Sheets("UIC").Range("C10:L10")
    .Value = .Value
End With
 
Upvote 0

bewsh1987

Board Regular
Joined
Sep 3, 2013
Messages
232
ADVERTISEMENT
Change your cases to something like this
Code:
Case 1
Sheets("UIC").Range("C10:L10").Copy Destination:=Range("C11")
With Sheets("UIC").Range("C10:L10")
    .Value = .Value
End With


try the below

Code:
Sub UIC()
Value = Mid(Sheets("Fs").Range("A9").Value, 6, 1) + 9
Valu2 = "C" & Value & ":L" & Value
Value3 = "C" & Value + 1
Sheets("UIC").Range(Valu2).Copy Destination:=Range(Value3)
With Sheets("UIC").Range(Valu2)
    .Value = .Value
End With

End Sub
 
Upvote 0

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,772
Ok..i 'm lost but i'll try..thanks anyway njimack..

Given the code you posted, you don't need to use Select Case. The value you're testing is an integer (1,2,3) and at each change in this, you're incrementing the row you're copying/pasting by 1.
 
Upvote 0

Zurina

New Member
Joined
Aug 21, 2013
Messages
9
Change your cases to something like this
Code:
Case 1
Sheets("UIC").Range("C10:L10").Copy Destination:=Range("C11")
With Sheets("UIC").Range("C10:L10")
    .Value = .Value
End With

Michael, i have Case 1 - 12, should i put the
n = Sheets("Fs"). Range ("A9").Value
Sheets("UIC").Range("C:L" & n + 10)..blabla
 
Upvote 0

Forum statistics

Threads
1,195,600
Messages
6,010,650
Members
441,558
Latest member
lambierules

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
Top