To make code more efficient

Fin Fang Foom

Well-known Member
Joined
Mar 20, 2005
Messages
598
Hi everyone,

I recorded a macro. What I did I click inside the cells and hit enter. I stop the macro and it gave me this code. Does anyone knows a faster way of doing this ? I need a range say B2:B3000.

Code:
  Range("B2").Select
    ActiveCell.FormulaR1C1 = "ProdType1"
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "ProdType2"
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "ProdType2"
    Range("B5").Select
    ActiveCell.FormulaR1C1 = "ProdType2"
    Range("B6").Select
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Code:
With Range("B2")
    .Value = "ProdType1"
    .AutoFill .Resize(5)
End With

Oops,
should be
Code:
With Range("B2")
    .Value = "ProdType1"
    .Offset(1).Resize(3000 - 2) = "ProdType2"
End With
 
Upvote 0

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, Fin Fang Foom !

or did you mean this
Code:
With Range("B2:B300")
.FormulaR1C1 = "=""ProdType"" & row() - 1"
.Value = .Value
End With

kind regards,
Erik

Hi, jindon
 
Upvote 0

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
ADVERTISEMENT
Erik,

I thought it would be like that, but his code....

With Range("B2")
.Value = "ProdType1"
.AutoFill .Resize(3000-1)
End With
 
Upvote 0

Fin Fang Foom

Well-known Member
Joined
Mar 20, 2005
Messages
598
I like both of your codes and it works fine. But what I was trying to do it instead of me clicking inside of each cell and hit enter for each of them it will activate the worksheet event code in my worksheet.

So I found this code and it works fine now. But both of you provided the codes that I will use.

Thanks!


Code:
Sub Activate_Cell()
Range("B2").Select
ActiveCell.Value = Range("B2:B3000").Value
End Sub
 
Upvote 0

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Code:
Sub Activate_Cell() 
Range("B2").Select 
ActiveCell.Value = Range("B2:B3000").Value 
End Sub
what is this supposed to do ?
you cannot put 3000 values in one cell :confused:
for me this code doesn't do anything: or do I miss something ?

best regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,195,680
Messages
6,011,124
Members
441,586
Latest member
rodsin76

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