[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

Enter values in one range based upon values in another range...

Whenever "(1)" [without " "] shows up in range AQ102:AQ141 I would like VBA code to enter 0 [zero] in the corresponding cell in range AQ59:AQ98.
0
ronadair
Asked:
ronadair
  • 4
  • 3
1 Solution
 
GrahamSkanRetiredCommented:
Do you mean like this?
    Dim cl As Range
    For Each cl In ActiveSheet.Range("AQ102:AQ141").Cells
        If cl.Value = "(1)" Then
            cl.Offset(59 - 102, 0).Value = 0
        End If
    Next cl

Open in new window

0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Your specs are a little vague, but if AQ102:AQ141 are text formatted cells, the following formula will provide the zero for the corresponding cell(s).

=IF(AQ102 = "(1)",0,"")
once you have entered the formula in cell AQ59, just select the cell and drag the lower right corner down thru cell AQ98. This will copy the formula to the remaining cells.
0
 
ronadairAuthor Commented:
Graham -

I tried the code but it won't execute.  The line
If cl.Value = "(1)" Then
is highlighted in yellow.

Division produces the values in AQ102:AQ141 & a few of them come up #DIV/0!.  Could this be screwing up the code?

Ron

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
GrahamSkanRetiredCommented:
Yes. I wasn't expecting that. Try cl.Text  instead of cl.Value.
0
 
ronadairAuthor Commented:
Graham -

I tried the change... still no cigar.  ;>(

Ron
0
 
ronadairAuthor Commented:
Graham -
I got rid of the #DIV/0! error with the formula
=IF(OR(Y59=0,AB8=0),0,Y59/AB8)
Your solution now works.

Thanks.
0
 
ronadairAuthor Commented:
Graham -

I fixed the #DIV/0! issue & the code worked with a minor adjustment.  Back to cl.Value and "-1" rather than "(1)".

Thanks,

Ron
0
 
GrahamSkanRetiredCommented:
Yes if you simply enter (1) into a cell, it is converted to -1, but if you enter '(1), you will get the text - less the apostrophe.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now