I've got a massive Excel 2003 spreadsheet I'm working on. There are a lot of very large formulas with a lot of cell references. Here's a simple example.
='Sheet'!AC69+'Sheet'!AC52+'Sheet'!AC53)*$D$3+'Sheet'!AC49
Most of them are more complicated than that, but this gives a good idea of what I'm working with. Few of these cell references are absolute ($s). I'd like to be able to copy these cells to a different location without the cell references changing. I know I can simply use f4 to make the references absolute, but there is a lot of data and I may need to use Fill later. Is there any way to temporarily disable the cell reference changing on copy-paste/fill without making the references absolute?
EDIT: I just found out that you can do this with VBA by copying the cell contents as text instead of a formula. I'd like to not have to do this though because I want to copy whole rows/columns at once. Is there a simple solution I am missing?
From http://spreadsheetpage.com/index.php/tip/making_an_exact_copy_of_a_range_of_formulas_take_2:
Put Excel in formula view mode. The easiest way to do this is to press Ctrl+` (that character is a "backwards apostrophe," and is usually on the same key that has the ~ (tilde).
Select the range to copy.
Press Ctrl+C
Start Windows Notepad
Press Ctrl+V to past the copied data into Notepad
In Notepad, press Ctrl+A followed by Ctrl+C to copy the text
Activate Excel and activate the upper left cell where you want to paste the formulas. And, make sure that the sheet you are copying to is in formula view mode.
Press Ctrl+V to paste.
Press Ctrl+` to toggle out of formula view mode.
Note: If the paste operation back to Excel doesn't work correctly, chances are that you've used Excel's Text-to-Columns feature recently, and Excel is trying to be helpful by remembering how you last parsed your data. You need to fire up the Convert Text to Columns Wizard. Choose the Delimited option and click Next. Clear all of the Delimiter option checkmarks except Tab.
Or, from http://spreadsheetpage.com/index.php/tip/making_an_exact_copy_of_a_range_of_formulas/:
If you're a VBA programmer, you can simply execute the following code:
With Sheets("Sheet1")
.Range("A11:D20").Formula = .Range("A1:D10").Formula
End With
A very simple solution is to select the range you wish to copy, then Find and Replace (Ctrl + h), changing = to another symbol that is not used in your formula (e.g. #) - thus stopping it from being an active formula.
Then, copy and paste the selected range to it's new location.
Finally, Find and Replace to change # back to = in both the original and new range, thus restoring both ranges to being formulae again.
I came to this site looking for an easy way to copy without changing cell references. But now I thnk my own workaround is simpler than most of these methods. My method relies on the fact that Copy changes references but Move doesn't. Here's a simple example.
Assume you have raw data in columns A and B, and a formula in C (e.g. C=A+B) and you want the same formula in column F but Copying from C to F leads to F=D+E.
Copy contents of C to any empty temporary column, say R. The relative references will change to R=P+Q but ignore this even if it's flagged as an error.
Go back to C and Move (not Copy) it to F. Formula should be unchanged so F=A+B.
Now go to R and copy it back to C. Relative reference will revert to C=A+B
Delete the temporary formula in R.
Bob's your uncle.
I've done this with a range of cells so I imagine it would work with virtually any level of complexity. You just need an empty area to park the coiped cells. And of course you have to remember where you left them.
This simple trick works: Copy and Paste. Do NOT cut and paste. After you paste, then reselect the part you copied and go to EDIT, slide down to CLEAR, and CLEAR CONTENTS.
Simple workaround I used just now while in a similar situation:
Make a duplicate of the worksheet.
Cut + Paste the cells with formulas from the duplicate worksheet (e.g. Copy of Sheet1) into the original worksheet.
Remove all occurrences of the the duplicate sheet's name from the newly pasted formulas; e.g. find-and-replace all occurrences of the search term 'Copy of Sheet1'! with an empty string (i.e. blank).
Delete duplicate worksheet to clean up.
Note: if your sheet name lacks spaces you won't need to use the single quote/apostrophe (').
Your cell references are now copied without being altered.
I think that you're stuck with the workaround you mentioned in your edit.
I would start by converting every formula on the sheet to text roughly like this:
Dim r As Range
For Each r In Worksheets("Sheet1").UsedRange
If (Left$(r.Formula, 1) = "=") Then
r.Formula = "'ZZZ" & r.Formula
End If
Next r
where the 'ZZZ uses the ' to signify a text value and the ZZZ as a value that we can look for when we want to convert the text back to being a formula. Obviously if any of your cells actually start with the text ZZZ then change the ZZZ value in the VBA macro to something else
When the re-arranging is complete, I would then convert the text back to a formula like this:
For Each r In Worksheets("Sheet1").UsedRange
If (Left$(r.Formula, 3) = "ZZZ") Then
r.Formula = Mid$(r.Formula, 4)
End If
Next r
One real downside to this method is that you can't see the results of any formula while you are re-arranging. You may find that when you convert back from text to formula that you have a slew of #REF errors for example.
It might be beneficial to work on this in stages and convert back to formulas every so often to check that no catastrophes have occurred
It's common to use find/ replace to disable formulas whilst performing manipulations. For example, copy with transpose. The formula is disabled by placing some placeholder (e.g. "$=") in front of it. Find replace can get rid of these once the manipulation is complete.
This vba just automates the find/ replace for the active sheet.
' toggle forumlas on active sheet as active/ inactive
' by use of "$=" prefix
Sub toggle_active_formulas()
Dim current_calc_method As String
initial_calc_method = Application.Calculation
Application.Calculation = xlCalculationManual
Dim predominant As Integer
Dim c As Range
For Each c In ActiveSheet.UsedRange.Cells
If c.HasFormula Then
predominant = predominant + 1
ElseIf "$=" = Left(c.Value, 2) Then
predominant = predominant - 1
End If
Next c
If predominant > 0 Then
For Each c In ActiveSheet.UsedRange.Cells
On Error Resume Next
If c.HasFormula Then
c.Value = "$" & c.Formula
End If
Next c
Else
For Each c In ActiveSheet.UsedRange.Cells
On Error Resume Next
If "$=" = Left(c.Value, 2) Then
c.Formula = Right(c.Value, Len(c.Value) - 1)
End If
Next c
End If
Application.Calculation = initial_calc_method
End Sub
This macro does the whole job.
Sub Absolute_Reference_Copy_Paste()
'By changing "=" in formulas to "#" the content is no longer seen as a formula.
' C+S+e (my keyboard shortcut)
Dim Dummy As Range
Dim FirstSelection As Range
Dim SecondSelection As Range
Dim SheetFirst As Worksheet
Dim SheetSecond As Worksheet
On Error GoTo Whoa
Application.EnableEvents = False
' Set starting selection variable.
Set FirstSelection = Selection
Set SheetFirst = FirstSelection.Worksheet
' Reset the Find function so the scope of the search area is the current worksheet.
Set Dummy = Worksheets(1).Range("A1:A1").Find("Dummy", LookIn:=xlValues)
' Change "=" to "#" in selection.
Selection.Replace What:="=", Replacement:="#", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Select the area you want to paste the formulas; must be same size as original
selection and outside of the original selection.
Set SecondSelection = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
Set SheetSecond = SecondSelection.Worksheet
' Copy the original selection and paste it into the newly selected area. The active
selection remains FirstSelection.
FirstSelection.Copy SecondSelection
' Restore "=" in FirstSelection.
Selection.Replace What:="#", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Select SecondSelection.
SheetSecond.Activate
SecondSelection.Select
' Restore "=" in SecondSelection.
Selection.Replace What:="#", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Return active selection to the original area: FirstSelection.
SheetFirst.Activate
FirstSelection.Select
Application.EnableEvents = True
Exit Sub
Whoa:
' If something goes wrong after "=" has been changed in FirstSelection, restore "=".
FirstSelection.Select
Selection.Replace What:="#", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
Note that you must match the size and shape of the original selection when you make your new selection.
I found this solution which automates #Alistair Collins solution.
Basically you will change the = in any formula to * then do the paste after that you will change it back
Dim cell As Range
msgResult = MsgBox("Yes to lock" & vbNewLine & "No unlock ", vbYesNoCancel + vbQuestion, "Forumula locker")
If msgResult = vbNo Then
For Each cell In Range("A1:i155")
If InStr(1, cell.Value, "*") > 0 Then
cell.Formula = Replace(cell.Formula, "*", "=")
End If
Next cell
ElseIf msgResult = vbYes Then
For Each cell In Range("A1:i155")
If cell.HasFormula = True Then
cell.Formula = Replace(cell.Formula, "=", "*")
End If
Next cell
End If
Try this:
Left-click the tab, making a copy of the whole sheet, then cut the cells you want to keep the same and paste them into your original worksheet.
I found another workaround that is very simple:
1. Cut the contents
2. Paste them in the new location
3. Copy the contents that you just pasted into the new location you want.
4. Undo the Cut-Paste operation, putting the original contents back where you got them.
5. Paste the contents from the clipboard to the same location. These contents will have the original references.
It looks like a lot, but is super fast with keyboard shortcuts:
1. Ctrl-x, 2. Ctrl-v, 3. Ctrl-c, 4. Ctrl-z, 5. Ctrl-v
Haven't check in Excel, but this works in Libreoffice4:
The whole thing of address rewriting comes during consecutive
(a1) cut
(a2) paste
You need to interrupt the consecutiveness by putting something in-between:
(b1) cut
(b2) select some empty cells (more than 1) and drag(move) them
(b3) paste
Step (b2) is where the cell that is about to update itself stops the tracking. Quick and simple.
Click on the cell you want to copy. In the formula bar, highlight the formula.
Press Ctrl C.
Press escape (to take you out of actively editing that formula).
Choose new cell. Ctrl V.
Related
Original Problem:
Within Azure Data Studio, I have saved the results of a SQL query into Excel spreadsheet. When I bring up the spreadsheet, a cell containing a formula (a URL hyperlink) is showing as text to display as opposed to results of executing the formula (a named visibly clickable hyperlink).
Here's the first three rows of raw data from the spreadsheet:
sourceTableNameA
sourceTableComposedKeyA
sourceTableComposedKeyA2
sourceTableNameB
sourceTableComposedKeyB
FCC_ASR_LI_20210202
=Hyperlink("https://maps.google.com/maps?q=28.537266254426,-97.794735431672","C.2655506")
https://maps.google.com/maps?q=28.537266254426,-97.794735431672
F3GIS_20210209
=Hyperlink("https://maps.google.com/maps?q=28.537266254426,-97.794735431672","{F4C8C17C-0702-4B08-ABC5-7ABF0BD76BAA}")
FCC_ASR_LI_20210202
=Hyperlink("https://maps.google.com/maps?q=29.709928035737,-96.912009716035","C.616145")
https://maps.google.com/maps?q=29.709928035737,-96.912009716035
F3GIS_20210209
=Hyperlink("https://maps.google.com/maps?q=29.709928035737,-96.912009716035","{7F77EAB2-3588-4023-921F-4C009FC91BDC}")
Solution A:
By clicking into the cell (ex: B2 above) and then pressing Return, the cell then turns into the results of the formula.
New Problem:
I have +20K of cells which I need to execute "Solution A". And manually executing "Solution A" +20K times is not an option.
Solution B (barely adequate):
After investing considerable time trying to fix this, I discovered a marginal solution. It is to select the contents of the column containing the formula-as-text, then search/replace the "=" character. While this does in fact convert the text into an actual formula for each cell, it leaves each cell looking like regular text instead of making it have the default appearance of a clickable link. This is causing me to have to then manually underline and select a different color for all of these cells.
Solution C (possible?):
My first thought was this is a job for an Excel Macro in VBA. And this is as close as I was able to get:
Public Sub Convert_To_Hyperlinks()
Dim Cell As Range
For Each Cell In Intersect(Selection, ActiveSheet.UsedRange)
If Cell <> "" Then
If Left(Cell, 1) = "=" Then
Evaluate (Cell)
Else
ActiveSheet.Hyperlinks.Add Cell, Cell.Value
End If
End If
Next
End Sub
This function works exactly as I need for cells (ex: C2 above) that contain a raw URL (i.e. the cell does not start with "=" character) which calls the ActiveSheet.Hyperlinks.Add Cell, Cell.Value for each cell giving the desired result. However, the code that detects if the cell (ex: B2 above) starts with "=" which calls Evaluate (Cell) doesn't work on the selected cells.
What VBA code can I use to replace Evaluate (Cell), if any, which would produce the same effect as Solution A?
In projects I have worked on I have found the following is often sufficient:
Cell.Value = Cell.Value
The beauty is that you can apply to ranges in one line.
Applying to your code with the loop:
Public Sub Convert_To_Hyperlinks()
Dim Cell As Range
For Each Cell In Intersect(Selection, ActiveSheet.UsedRange)
If Cell <> vbNullString Then
If Left$(Cell, 1) = "=" Then
Cell.Value = Cell.Value
Else
ActiveSheet.Hyperlinks.Add Cell, Cell.Value
End If
End If
Next
End Sub
My problem is that an Excel spreadsheet (exported from Access as .xls) has cells that look empty, but are not. This is mucking up my calculations & navigation shortcuts.
There are no formulae or contents in the cells (the answers already posted on this topic don't fix my problem). I've attached an image of my problem (see bottom)
Troubleshooting shows:
If I test these cells e.g. =isblank(a1), it's FALSE.
The cell lengnth is 0, according to =LEN(a1)
If I try 'Go to (special) highlight "Blanks" (or any other go to special combination like formula/text,numbers, etc) it will NOT highlight these empty looking cells
YET if I filter the column, I can select these non-empty "blanks" from the filter list (this is the only way to identify these tricky cells I've found so far) -
So my column has entries in some cells, "blank" non-empty cells. I only want the cells with entries, the rest I need cleared. This also annoyingly means the shortcut to skip to the next empty or nonempty cell wont work (it reads all as nonblank) - making it super painful to navigate the large dataset.
Once I click within an individual 'non-empty' blank cell & press enter, this seems to clear the cell contents ('=isblank' formula's that were saying "FALSE" now switch to 'TRUE') - this is not feasible to fix individual cells in such a large dataset though.
Can ANYONE help?!
I have found 2 basic workarounds that fix this, but I really want to know how & why this happens & how to avoid it in future.
Workaround 1
In excel, filter the column, show only "blank", then highlight the filtered column & press delete. Unfilter the list & the problems solved.
Workaround 2
save the excel spreadsheet from 'file.xlsx' & save as '.csv'.
Close it all, open the csv & it seems the non-empty blank cells are fixed, show =isblank= TRUE & can be skipped with [CNTL arrow key] shortcuts now.
This is so frustrating & I haven't seen any similar questions nor answers on why this is?
Why is this happening & are there any other fixes around for this?
Thanks hive-mind!
excel sheet shows non-blank empty cells - working
Sometimes it's nice to have the ctrl+up/down stop at the edge of the data set other times it's not; here's the macro I use to clear the selected range's "blank" cells for when it's not:
'clears cells with error or empty string values
Public Sub clearJunk()
Dim scrn As Boolean: scrn = Application.ScreenUpdating: Application.ScreenUpdating = False
Dim i As Long, rowCount As Long, FirstRow As Long
Dim col As Range
rowCount = Selection.Columns(1).Cells.count
FirstRow = Selection.Cells(1).Row - 1
For Each col In Selection.Columns
For i = 1 To rowCount
If IsEmpty(col.Cells(i)) Then i = col.Cells(i).End(xlDown).Row - FirstRow
If i > rowCount Then Exit For
If IsError(col.Cells(i).Value) Then
col.Cells(i).ClearContents
ElseIf col.Cells(i).Value = "" Then
col.Cells(i).ClearContents
ElseIf Trim(col.Cells(i).Value) = "" Then
col.Cells(i).ClearContents
End If
Next i
Next col
Application.ScreenUpdating = scrn
End Sub
Also if you're copying and pasting from MS-Access you might find this one useful too:
Public Sub UnWrapText(): Selection.WrapText = False: End Sub
I've bound both to buttons on my Ribbon/QAT and it's made my life more hassle free.
You can also try the below:
Select your region.
In the "Find & Replace" dialog box, leave the "Find what:" box empty.
Enter any value that doesn't exist yet in your data, e.g. a pipe ("|") in the "Replace with:" box.
Check the "Match entire cell contents" option.
"Replace All"
Now, enter the pipe in the "Find what:" box, and clear the "Replace with:" box.
"Replace All", and you're done!
Source: https://www.mrexcel.com/board/threads/how-to-remove-null-string-from-cells.565955/ (A bit updated by me)
Just save you excel file as an csv file. Then create in Access a linked table to the csv file. When you create a query to import your data then values which look empty in excel will have a NULL value in Access.
I'm trying to get rid of the blank cells between my cells which have info in them by using F5 to find the blank cells, then Ctrl + - to delete them, and shift the cells up. But when I try to do that, it tells me that there are 'No cells found'.
I've noticed that if I select my 'blank' cells, Excel still counts them: which is weird. But if I press Delete on those selected cells, the count goes away, and then I can go F5, blanks, Ctrl + - and Shift cells up, and it works...
So my question is how can I still do that, but with these blank cells which Excel thinks aren't blank? I've tried to go through and just press delete over the blank cells, but I have a lot of data and realized that it would take me WAY too long. I need to find a way to select these 'blank' cells within a selection of data.
a simple way to select and clear these blank cells to make them blank:
Press ctrl + a or pre-select your range
Press ctrl + f
Leave find what empty and select match entire cell contents.
Hit find all
Press ctrl + a to select all the empty cells found
Close the find dialog
Press backspace or delete
This worked for me:
CTR-H to bring up the find and replace
leave 'Find What' blank
change 'Replace with' to a unique text, something that you are
positive won't be found in another cell (I used 'xx')
click
'Replace All'
copy the unique text in step 3 to 'Find what'
delete the unique text in 'Replace with'
click 'Replace All'
A revelation: Some blank cells are not actually blank! As I will show cells can have spaces, newlines and true empty:
To find these cells quickly you can do a few things.
The =CODE(A1) formula will return a #VALUE! if the cell is truly empty, otherwise a number will return. This number is the ASCII number used in =CHAR(32).
If you select the cell and click in the formula bar and use the cursor to select all.
Removing these:
If you only have a space in the cells these can be removed easily using:
Press ctrl + h to open find and replace.
Enter one space in the find what, leave replace with empty and ensure you have match entire cell contents is ticked in the options.
Press replace all.
If you have newlines this is more difficult and requires VBA:
Right click on the sheet tab > view code.
Then enter the following code. Remember the Chr(10) is a newline only replace this as required, e.g. " " & Char(10) is a space and a newline:
Sub find_newlines()
With Me.Cells
Set c = .Find(Chr(10), LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = ""
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address <> firstAddress
End If
End With
End Sub
Now run your code pressing F5.
After file supplied: Select the range of interest for improved performance, then run the following:
Sub find_newlines()
With Selection
Set c = .Find("", LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = ""
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address <> firstAddress
End If
End With
End Sub
All, this is pretty simple. I have been trying for the same and this is what worked for me in VBA
Range("A1:R50").Select 'The range you want to remove blanks
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Regards,
Anand Lanka
I had a similar problem where scattered blank cells from an export from another application were still showing up in cell counts.
I managed to clear them by
Selecting the columns/rows I wanted to clean, then doing
"Find" [no text] and "Replace" [word of choice].
Then I did "Find" [word of choice] and "Replace" with [no text].
It got rid of all hidden/phantom characters in those cells. Maybe this will work for you?
If you don't have formatting or formulas you want to keep, you can try saving your file as a tab delimited text file, closing it, and reopening it with excel. This worked for me.
Not sure if this has already been said, but I had a similar problem with cells showing nothing in them, but not being blank when you run the IsBlank() formula.
I selected the entire column, selected Find & Replace, found cells with nothing and replaced with a 0, then ran find and replace again, finding cells with 0 and replacing with "".
This solved my problem and allowed me to search for Blank cells (F5, Special, Blanks) and delete rows that were blank....BOOM.
May not work for every application but this solved my problem.
Sometimes there are spaces in cells which appear blank but if you hit F2 on the cell, you'll see spaces. You can also search this way if you know the exact number of spaces in a cell
The most simple solution for me has been to:
1)Select the Range and copy it (ctrl+c)
2)Create a new text file (anywhere, it will be deleted soon), open the text file and then paste in the excel information (ctrl+v)
3)Now that the information in Excel is in the text file, perform a select all in the text file (ctrl+a), and then copy (ctrl+c)
4)Go to the beginning of the original range in step 1, and paste over that old information from the copy in step 3.
DONE! No more false blanks! (you can now delete the temp text file)
'Select non blank cells
Selection.SpecialCells(xlCellTypeConstants, 23).Select
' REplace tehse blank look like cells to something uniqu
Selection.Replace What:="", Replacement:="TOBEDELETED", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'now replace this uique text to nothing and voila all will disappear
Selection.Replace What:="TOBEDELETED", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Found another way. Set AutoFilter for all columns (important or you will misalign data) by selecting the header row > 'Data' tab > Sort and filter - 'Filter'. Use drop-down in first data column, untick 'Select all' and select only '(Blanks)' option > [OK]. Highlight rows (now all together) > right click > 'Delete row'. Head back to the drop-down > 'Select all'. Presto :)
This works with numbers.
If your range is O8:O20, then in a nearby empty range (e.g. T8:T20) enter =O8/1 and fill down. This will give you a result of #VALUE for the 'empty' cells and your original number will remain as it was.
Then with the range T8:20 selected (CTL-* if it's not already) hit F5 and choose Special. From the Special dialogue, choose Errors and click OK. This will deselect your actual numbers leaving only the #VALUE cells selected. Delete them and you will have actual empty cells. Copy T8:T20 and paste back over O8:O20.
Essentially, since blank cells doesn't work, you need to convert the 'empty' cells into something that the Go To Special can latch on to. Any action that would convert into #VALUE would work, and other 'error' types should be supported as well.
My method is similar to Curt's suggestion above about saving it as a tab-delimited file and re-importing.
It assumes that your data has only values without formulas.
This is probably a good assumption because the problem of "bad" blanks is caused by the confusion between blanks and nulls -- usually in the data imported from some other place -- so there shouldn't be any formulas.
My method is to parse in place -- very similar to saving as a text file and re-importing, but you can do this without closing and re-opening the file.
It's under Data > Text-to-Columns > delimited > remove all parsing characters (can also choose Text if you want) > Finish. This should cause Excel to re-recognize your data from scratch or from text and recognize blanks as really blank.
You can automate this in a subroutine:
Sub F2Enter_new()
Dim rInput As Range
If Selection.Cells.Count > 1 Then Set rInput = Selection
Set rInput = Application.InputBox(Title:="Select", prompt:="input range", _
Default:=rInput.Address, Type:=8)
' Application.EnableEvents = False: Application.ScreenUpdating = False
For Each c In rInput.Columns
c.TextToColumns Destination:=Range(c.Cells(1).Address), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, _
FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Next c
Application.EnableEvents = True: Application.ScreenUpdating = True
End Sub
You can also turn-on that one commented line to make this subroutine run "in the background". For this subroutine, it improves performance only slightly (for others, it can really help a lot).
The name is F2Enter because the original manual method for fixing this "blanks" problem is to make Excel recognize the formula by pushing F2 and Enter.
Here's how I fixed this problem without any coding.
Select the entire column that I wanted to delete the "blank" cells from.
Click the Conditional Formatting tab up top.
Select "New Rule".
Click "Format only cells that contain".
Change "between" to "equal to".
Click the box next to the "equal to" box.
Click one of the problem "blank" cells.
Click the Format Button.
Pick a random color to fill the box with.
Press "OK".
This should change all of the problem "blank" cells to the color that you chose. Now Right click one of the colored cells, and go to "Sort" and "Put selected cell color on top".
This will put all of the problem cells at the top of the column and now all of your other cells will stay in the original order you put them in. You can now select all of the problem cells in one group and click the delete cell button on top to get rid of them.
Goto->Special->blanks does not like merged cells. Try unmerging cells above the range in which you want to select blanks then try again.
I had a similar problem with getting the COUNTA formula to count non-blank cells, it was counting all of them (even the blank one's as non-blank), I tried =CODE() but they had no spaces or new lines.
I found that when I clicked in the cell and then clicked out of it then the formula would count the cell. I had thousands of cells so could not do this manually. I wrote this VBA statement to literally check all the cells and if they were blank then to make them blank. Ignore the pointlessness of this macro and trust me that it actually worked by forcing Excel to recognize the empty cells as actually being empty.
'This checks all the cells in a table so will need to be changed if you're using a range
Sub CreateBlanks()
Dim clientTable As ListObject
Dim selectedCell As Range
Set clientTable = Worksheets("Client Table").ListObjects("ClientTable")
For Each selectedCell In clientTable.DataBodyRange.Cells
If selectedCell = "" Then
selectedCell = ""
End If
Next selectedCell
End Sub
Save your dataset in CSV file and open that file and copy the dataset and paste to the excel file.
and then crtl + g will work on your file, means the excel will recognize that blank is really blank.
I am tasked with creating A map of our warehouse.
In the data I have to have model, description and location.
What I am having trouble with is, I am using data from a second sheet to populate the "map"
i.e. ='1'!F2
when I try to drag and use it to fill an entire line it changes to ='1'!g2. I would like it to go to ='1'!F3
I see the logic in what it is doing...but I dont want it to use that logic..I want it to use the next cell below it to populate that cell.
The simplest thing might be to Copy and then Paste Special > Transpose the data on "1" to a new sheet. Then you could drag formulas that refer to the new sheet and they'd behave as expected.
EDIT: Based on your original question, this will fill in the results of columns to the right as you drag it down and vice-versa. This literally does what your original question asked:
=INDEX(Sheet1!$F$2:$Z$8000,COLUMN(),ROW())
Start in A1 and drag in either direction. To add a header line or rows to left just insert rows or columns to top or left (to keep the formula sound).
EDIT: Here's the Transpose function, per #brettdj's suggestion. I find it difficult to work with, but it certainly makes it clearer what's going on:
In cells F2:8000 of your target sheet enter:
=TRANSPOSE(Sheet1!$F2:$Z8000)
Then, with all those cells selected, go into edit mode in one of the cells and do Ctrl Shft Enter to array-enter it. If you have to resize the source range I believe you have to repeat these steps with the correct ranges. I'm an Index fan myself, so would stick with that. Offset is volatile, so I'd avoid it. If I've got any of this last edit wrong, #brettdj will help us.
Since what you want is non-native behaviour, it might be worth writing a small VBA macro to do the copy, and assign it to a keyboard shortcut.
Here's a simple example to copy a formula one cell to right, updating reference one cell down (preserves Absolute/Relative settings in formula).
It assumes A1 style address, work only if the active cell contains a formula referencing a single cell (ends silently if not). Will silently overwrite anything in the destination cell.
Sub CopyToRight()
Dim clFrom As Range
Dim clAddr As Range
Dim addr As String
On Error GoTo EH
Set clFrom = ActiveCell
If clFrom.Formula Like "=*!*" Then
Set clAddr = Range(Mid(clFrom.Formula, 2))
If clAddr.Count = 1 Then
If clFrom.Formula Like "=*!$*$*" Then
addr = clAddr.Offset(1, 0).Address(True, True)
ElseIf clFrom.Formula Like "=*!$**" Then
addr = clAddr.Offset(1, 0).Address(False, True)
ElseIf clFrom.Formula Like "=*!*$*" Then
addr = clAddr.Offset(1, 0).Address(True, False)
Else
addr = clAddr.Offset(1, 0).Address(False, False)
End If
clFrom.Offset(0, 1).Formula = "='" & clAddr.Worksheet.Name & "'!" & addr
End If
End If
clFrom.Offset(0, 1).Select
EH:
End Sub
I'm a new convert from Experts-Exchange since I noticed they increased the 'Free Premium Services' points threshold.
It seems that Excel 2003 has issues with the End(xlup) command when using it in a worksheet that contains an Excel 'List'.. If I select a cell outside the 'list' boundary, and then try to select the last cell in the worksheet by using VBA, I have to call the .Select function twice to make sure I am getting the correct cell. If the original cell is inside the 'list' boundary then i only need one .Select. My hacked together solution is below, with two selects, as I can never be sure what cell may be selected on save. I include a version check at open to run different code in Excel 2007 (this code fails in 2007, where the .End(xlUp) command works properly).
Is there a more eloquent way to handle this?
Thanks for any help!
.Range("A1").Select
.Cells(.Rows.Count, "A").End(xlUp).Select
.Cells(.Rows.Count, "A").End(xlUp).Select
'two .Selects needed to select correct cell in Excel 2003 list because original selection (A1) was not in list'
.Range("A1").Select
.Cells(.Rows.Count, "T").End(xlUp)(-2, 1).Select
.Cells(.Rows.Count, "T").End(xlUp)(-2, 1).Select
'two .Selects needed to select correct cell in Excel 2003 list because original selection (A1) was not in list'
.Cells(.Rows.Count, "T").End(xlUp)(-3, 1).Select
'only one select needed here because original selection above was within the list'
See how this does:
Sub Example()
Dim rngLstCell As Excel.Range
Set rngLstCell = GetLastCell(Excel.Worksheets("Sheet1"))
MsgBox "The last cell is: " & rngLstCell.Address, vbInformation
End Sub
Public Function GetLastCell(ByVal ws As Excel.Worksheet) As Excel.Range
Dim rngRtnVal As Excel.Range
With ws.UsedRange
Set rngRtnVal = .Find("*", .Cells(1, 1), , , xlByRows, xlPrevious)
If rngRtnVal Is Nothing Then
Set rngRtnVal = .Cells(1, 1)
End If
End With
Set GetLastCell = rngRtnVal
End Function
Using find may seem weird at first but it ends up being the most reliable way due to some vagaries in the way empty cells are handled.
This may not be perfect if your data is non-normalized (jagged).
I found that my use of .End(xlUp).Select prior to acting on the .End(xlUp) cell was causing the problem. If I simply avoid the .End(xlUp).Select prior to operating on the .End(xlUp) cell, the problem is less complex. It can be easily solved by preceding any .End(xlUp) operation with .Range("A1").Select. See the code for explanation. This doesn't really fix the problem with improper .End(xlUp) cell 'selection' - but I'm not interested in 'selecting' the cells, just operating on them. I must mention that I use .Range("A1").Select because A1 is outside of the 'list' that I'm manipulating via VBA.
'commented out - just need to add a ".Range("A1").Select" prior to any .End(xlUp) usage (besides .End(xlUp).Select) to make it work in Excel 03
'.Range("A1").Select
'.Cells(.Rows.Count, "A").End(xlUp)(0, 1).Select
'.Cells(.Rows.Count, "A").End(xlUp)(0, 1).Select
''two .Selects needed to select correct cell in Excel 2003 'Lists'
'Set EntryDate = Cells(.Rows.Count, "A").End(xlUp)(0, 1) 'no need to select cell first, then operate on it, as in the code above
'fixed code below
.Range("A1").Select 'needed for Excel 03 to select correct cell
Set EntryDate = Cells(.Rows.Count, "A").End(xlUp) 'just operate on the cell instead of selecting it first
Are you sure the ranges that you were working with were identical? You shouldn't get different results using the End property in Excel 2007 versus 2003.
Looking at your code:
.Range("A1").Select
.Cells(.Rows.Count, "A").End(xlUp).Select
.Cells(.Rows.Count, "A").End(xlUp).Select
Each of these lines of code have exactly zero impact on one another. No honest explanation can be offered about why the End property is giving you different results based on the code you've provided. From what's written, you should get the same results each time. (That's assuming you're working with identical ranges.) I'd be suspicious of any other code that's being executed. I can offer a couple general tips though: If you use End starting with a blank cell, it will stop at the first non-blank cell. If you start with a non-blank cell, the opposite is true. Looking at the screenshot below:
Range("B13").End(xlUp).Select 'selects B12
Range("B12").End(xlUp).Select 'selects B2
Range("A12").End(xlUp).Select 'selects A6
So whether or not your list is contiguous is an issue. Also, it is not necessary to select a range before you do something to it. Telling Excel to select cell A1 does not impact how it executes .Cells(.Rows.Count, "A").End(xlUp).Select. Assuming that line is within a With block that refers to a worksheet, that line of code is the same thing as navigating to cell A65536 (or A1048576 in Excel 2007) and pressing Ctrl + Up. Assuming that cell is blank, Excel will navigate upwards until it finds the first non-blank cell in column A. If your With block refers to a range object, then that line of code will go to the first column, bottom row of that range and navigate upwards until it comes to the first blank or non-blank cell.