Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Looking for an easy simple way to select an entire group of columns and rows and convert the text to "1"

Posted on 2011-09-13
9
182 Views
Last Modified: 2012-05-12
Looking for an easy simple way to select an entire group of columns and rows and convert the text to "1"

Please look at the attached Excel file for an example.
Excel-Question.xlsx
0
Comment
Question by:Donnie Walker
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 10

Expert Comment

by:SANTABABY
ID: 36531309
Example VBA:



Dim r As Range

Set r = Rows(15)
'or
Set r = Columns(1)

r.Cells.Value = 1
0
 

Author Comment

by:Donnie Walker
ID: 36531328
How would I do that in Excel and will that do multiple columns?
0
 
LVL 10

Expert Comment

by:SANTABABY
ID: 36531348
Change any one cell value to 1
Copy the above cell (ctrl+c)
Ctrl+Click or ctrl+Mouse Select all the cells/ranges that you want to update
Paste (ctrl+v)
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:Donnie Walker
ID: 36531367
That doesn't work the way I want. Some areas would have no data and this put in "1" everywhere.
0
 
LVL 5

Accepted Solution

by:
slycoder earned 250 total points
ID: 36531423
Try:

Put this macro in a module:

Public Sub ReplaceTextWithOne()
    For Each c In Selection
        If c.Value <> "" Then
            c.Value = "1"
        End If
    Next
End Sub


then select a range and run the macro.  Think this will do what you want.

0
 
LVL 3

Assisted Solution

by:heideld
heideld earned 250 total points
ID: 36531429
Highlight desired columns and rows, press CTRL F (to find) choose the replace tab...

put a * in "Find What"
and a 1 in Replace with:

press replace all:
0
 
LVL 3

Expert Comment

by:heideld
ID: 36531445
You said you wanted simple.....  and you can select multiple groups of columns and rows by holding the  the ctrl key
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36531464
Getting more complex - if you have cells that contain text, blanks and values and you wish to only replace the "TEXT" cells with a "1"

The ReplaceExclusiveTextWithOne is your function.


Public Sub ReplaceExclusiveTextWithOne()
    For Each c In Selection
   
        If CellType(c) = "Text" Then
            c.Value = "1"
        End If
    Next
End Sub

Function CellType(c)
    ' Source: http://j-walk.com/ss/excel/tips/tip62.htm
'   Returns the cell type of the upper left
'   cell in a range
    Application.Volatile
    Set c = c.Range("A1")
    Select Case True
        Case IsEmpty(c): CellType = "Blank"
        Case Application.IsText(c): CellType = "Text"
        Case Application.IsLogical(c): CellType = "Logical"
        Case Application.IsErr(c): CellType = "Error"
        Case IsDate(c): CellType = "Date"
        Case InStr(1, c.Text, ":") <> 0: CellType = "Time"
        Case IsNumeric(c): CellType = "Value"
    End Select
End Function



0
 

Author Closing Comment

by:Donnie Walker
ID: 36531471
Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question