ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Cell equals text Copy Cells, B2,B3,B4 (https://www.excelbanter.com/excel-programming/337802-if-cell-equals-text-copy-cells-b2-b3-b4.html)

Djmask[_5_]

If Cell equals text Copy Cells, B2,B3,B4
 

How can I detect a cell value in VBA if the cell is text? I want to set
an if statement based on the whether or not cell B7 equals USA.

So if cell B7 = "USA" then copy paste B4, B5, B6 to 1A, 2B, 4B,

If B7< "USA" then copy paste B4, B5, B6, B7 to 1A, 2B, 3B, 4B.

I'm new to programming but have made macros using macro record as well
as modifying some of the macros from examples on the internet. I can’t
seem to find the appropriate functions in VBA help or figure ot enough
from the examples on the site to accomplish what I want. Just a point
in the right direction would be greatly appreciated.

:: Description of what I'm trying to do ::
I have numerous invoices imported from .csv files in excel documents. I
would like to take the billing name shipping name etc and put them all
on one row. Unfortunately since the invoice is saved from a webpage the
Address 2 Field is dynamic I need to detect what kind of invoice it is
to copy the fields. All of our invoices have USA after the city, ST,
Zip cell. So by determining which cell USA is in I can copy paste the
appropriate cells into my row.

Thanks for any help or guidance.

Scott


--
Djmask
------------------------------------------------------------------------
Djmask's Profile: http://www.excelforum.com/member.php...o&userid=24414
View this thread: http://www.excelforum.com/showthread...hreadid=397433


hideki[_8_]

If Cell equals text Copy Cells, B2,B3,B4
 

what's the different between B4 and 4B? Does it copy to the same row in
the same worksheet?


--
hideki
------------------------------------------------------------------------
hideki's Profile: http://www.excelforum.com/member.php...o&userid=18903
View this thread: http://www.excelforum.com/showthread...hreadid=397433


jseven

If Cell equals text Copy Cells, B2,B3,B4
 
if range("B7").value = "USA" then
'what ever you want it to do here.
else
'what you want it to do if it doesn't equal "USA"
end if

Of course, if you want to do this to several cells in a range, you will
have to loop the code using a loop of some sorts.

For example:

x = 7
Do until range("B" & x).value = ""

if range("B7").value = "USA" then
'what ever you want it to do here.
else
'what you want it to do if it doesn't equal "USA"
end if

loop


Djmask[_6_]

If Cell equals text Copy Cells, B2,B3,B4
 

hideki,
Thanks for the response. I'm a little tired and mixed my example all
up. I've corrected the proper cell mapping in my original post.

scott


--
Djmask
------------------------------------------------------------------------
Djmask's Profile: http://www.excelforum.com/member.php...o&userid=24414
View this thread: http://www.excelforum.com/showthread...hreadid=397433


Information Hog[_3_]

If Cell equals text Copy Cells, B2,B3,B4
 

This should get you started

Dim MyCheck As String
MyCheck = "USA"
MyRange = Cells(7, 2)

If MyCheck = MyRange Then
' code for copy here
End If


--
Information Hog
------------------------------------------------------------------------
Information Hog's Profile: http://www.excelforum.com/member.php...o&userid=21508
View this thread: http://www.excelforum.com/showthread...hreadid=397433


Djmask[_7_]

If Cell equals text Copy Cells, B2,B3,B4
 

Thanks guys thats huge I can probably get this done today. Your examples
give me a better understanding of declaring ranges and strings also.


scott


--
Djmask
------------------------------------------------------------------------
Djmask's Profile: http://www.excelforum.com/member.php...o&userid=24414
View this thread: http://www.excelforum.com/showthread...hreadid=397433



All times are GMT +1. The time now is 06:53 PM.

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