vba Questions

tico_ocit

Board Regular
Joined
Apr 5, 2019
Messages
95
Code is generally slowed considerably by 'activating' and 'selecting'. Most time that is not necessary.

I don't know whether you actually need to activate ALL.xls to start with as I don't know what is in FTALLV however these lines of code

VBA Code:
Range("A11:BD11").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Can be replaced by these (not exactly sure of the name of that second workbook - spelling or extension - so check), avoiding any activation or selection or copy.
VBA Code:
Dim rws As Long

With Workbooks("ALL.xls").Sheets("FT")
  rws = .Range("A11:BD11").End(xlDown).Row - 10
  Workbooks("COMPARSION.xls").Sheets("FT COMPARE").Range("B23").Resize(rws, 56).Value = .Range("A11:BD11").Resize(rws).Value
End With

Sorry for entering the conversation, but we are always learning. @Peter_SSs can you answer me two questions? 1. I always use .activate instead of .select, because .select doesn't work, do you know why? 2. I didn't know this propoerty of range, "resize", it's great! But, the .value=.value only works if you are copying just the values, right?? Because I always can use range(A1:A3").copy Sheets("sheet2").range("B1:B3"). Is it faster? Or the same?
Thank you!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Firstly, I have moved your question to its own thread rather than hijacking another active one.

1. I always use .activate instead of .select, because .select doesn't work, do you know why?
It depends on what you are trying to activate/select. In most case you do not need to do either.


But, the .value=.value only works if you are copying just the values, right??
Correct


Because I always can use range(A1:A3").copy Sheets("sheet2").range("B1:B3"). Is it faster? Or the same?
Faster or the same as what?

If you mean compared to
Sheets("sheet2").Range("B1:B3").Value = Range(A1:A3").Value
then the question is not one of speed because the two codes do different things. The second copies values only
The first copies values or formulas depending what is in the source range. It also copies things like Formatting, Conditional Formatting, Data Validation, Comments, ... etc
 
Upvote 0
Faster or the same as what?

If you mean compared to
Sheets("sheet2").Range("B1:B3").Value = Range(A1:A3").Value
then the question is not one of speed because the two codes do different things. The second copies values only
The first copies values or formulas depending what is in the source range. It also copies things like Formatting, Conditional Formatting, Data Validation, Comments, ... etc

I understand, I started using .value=.value due to speeding. On the example that I gave: range(A1:A3").copy Sheets("sheet2").range("B1:B3") , it is possible, in the same line of code, choosing what to copy? Format, values, formulas?

Thank you for moving, and thank you for answering.
 
Upvote 0
On the example that I gave: range(A1:A3").copy Sheets("sheet2").range("B1:B3") , it is possible, in the same line of code, choosing what to copy? Format, values, formulas?
No. for that you need to Copy then on a separate code line use PasteSpecial to choose the elements to paste.
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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