How to copy a dropdown menu (data validation) to entire column in Excel (only rows that having something else too). And, in this case, how to leave row for the header?
Ok, I found the answer and now it's working:
Sub pasteCellToColumn()
Dim lastRow As Long, i As Long
lastRow = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
Sheets("hiddenData").Range("A1").Copy
For i = 1 To lastRow
If Len(Trim(Sheets("Sheet1").Range("A" & i).Value)) <> 0 Then
Sheets("Sheet1").Range("K" & i).PasteSpecial _
Paste:=xlPasteValidation
End If
Next i
End Sub
Instead of clicking in a cell, click on the header (A,B,C, etc) and go to: Data Tools > Data validation.
Select the entire column you want to validate
Click on "Data Validation" from the Data tab
Choose "List" from the "Allow" box
Click on the arrow to the right of the "Source" box and select the cells containing the allowed values
And you are good to go!
More on that here.
To copy and paste only the dropdown list (validation), and only to not empty cells, do the following:
Select every possible cell (including empty ones) where you want to have the dropdown menu pasted.
Hit F5, then Special..., finally Constants radio button and OK. This will select only cells which are not empty from your previous selection.
Home > Paste > Paste Special...
Validation radio button and lastly OK.
Let me know if it helps!
Related
For a work project I'm trying to build an excel sheet that lets a user input a number in a dialogue box (or cell) and once a confirmation button is pressed, all numbers in a specific range shall be incremented by the specific value entered by the user. My range is B2:B100 and all cells are either filled with numbers or are empty.
When the user completes his work they'd enter their value in e.g. cell J3 and then press a toggled button underneath. J3 will be cleared and all values in B2:B100 would be incremented by the number entered.
Any help or direction to resources that would cover this would be appreciated. Many thanks.
1) In Excel, Press Alt + F11
2) It will open the VBA editor. copy paste the following code in the editor.
Sub addNumbers()
Dim i As Long
Dim incrementValue As Long
incrementValue = Cells(3, 10).Value
For i = 2 To 100
Cells(i, 2).Value = Cells(i, 2).Value + incrementValue
Next i
End Sub
3)Save this code
4)Go to Developer --> Insert --> Form Controls (Button)
This will open the Assign MAcro window. Select addNumbers. Click on OK.
5) Now you can enter the Desired values in Cell J3 and then click on this button. It will increment Cells B2:B100 by that particular value.
i create some table, and make a datestamp when i enter data
in column "A" the date is shown in column "E" , so i know when data is entered.
I put checkbox in column "F", but I need help with next:
When checkbox is checked the date must be written in column "G"
The background from "A to D" (but only in this row) must be changed to red color
The data from A, B and C must be copied to another sheet also in A,B and C
I hope someone will help me because i stuck :(
I also attack a screenshot.
Thanks in advance
The procedures will help you get the macro operational, ensure you try the code on a copy of your workbook
Add a command button (ActiveX control) and paste the macro
Note: You need to ensure that you place the Command Button in the worksheet where you have your check boxes.
Step 1:
Copy the “LoopCkBoxesAddDateStampClrCelsCopy()” macro
Sub LoopCkBoxesAddDateStampClrCelsCopy()
Dim lRow As Long
Dim CkBx As OLEObject
'For/Next loop cycles through all checkboxes in worksheet
For Each CkBx In ActiveSheet.OLEObjects
lRow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
'If the checkbox is checked then accomplish the lines of code between the If/End If
'The part after the "And" ensures that if a date is in the cell it will not be over written
If CkBx.Object.Value = True And CkBx.TopLeftCell.Offset(, 1).Value = "" Then
'Next line of code puts the date in first cell to left of the checkbox
CkBx.TopLeftCell.Offset(, 1).Value = Format(Date, "mm-dd-yyyy")
'Next line of code colors the first 4 cells in checkboxs' row
CkBx.TopLeftCell.Offset(, -5).Resize(, 4).Interior.Color = vbRed
'Next line of code copies the first 3 cell in the checkbox row to the first empty row on sheet 2
Sheet2.Cells(lRow, 1).Offset(1).Resize(, 3).Value2 = CkBx.TopLeftCell.Offset(, -5).Resize(, 3).Value2
End If
Next CkBx 'loops to the next checkbox
End Sub
Note: If you plan on pasting your cells to a different worksheet, please change both Sheet2s in the code.
Step 2:
On the Developer tab, in the Controls group, click Insert, and then under ActiveX Controls, click the Command Button.
Step 3:
Click the worksheet location where you want the command button to appear.
Step 4:
Right click the button, click View Code. This will launch the Visual Basic Editor.
Step 5:
In the VBE, highlight the Private Sub CommandButton1_Click() and the End Sub, and Paste the macro
Step 6:
Close the Visual Basic Editor, and click Design Mode Button image to ensure design mode is off.
Step 7:
Select the checkboxes in your worksheet and click the button to run the macro
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.
Because the cells in my project contain so much data I have had to insert textboxes that have scrollbars to see all the data (they are linked to the cell which sit behind them on the spreadsheet). Is there any fast way to do the same thing on a column of 1000 records or will I have to go through manually and link the textbox to the specific cell? Is there a faster way?
Also If an issue comes in that is a reply to the original issue I need it to use the original ID (I have used auto IDS, which can be seen in the spreadsheet). Any recommendations?
Slowly I am getting better at excel and VBA but I need a hand sometimes ^_^
I have attached the spreadsheet which contains an example of 2 records I made. The final sheet will have 1000 records. (Please download the spreadsheet and open in excel)
LINK To Spreadsheet
A few things:
You should change the cell formatting to "Top Align" the text in the cells. This will cause the cell to show the first line of the long text in the Query cells.
Instead of using the "send email" text in a cell why not add a single button to email the currently selected row. (use insert on the ribbon in the developer tab (you have to change the excel options to show the developer tab).
The code to send an email might be better if it updated a new column with the date it was sent, and in the event that it has already been sent, it could prompt the user to confirm.
if not isempty(cells(r, ColNumberWithSentdate) ) then
if vbno = msgbox ("Are you sure you want to send the email again?", VbYesno) then
Exit sub
end if
end if
All the textboxes you have added are really slowing down the spreadsheet.
why not just have one tall row at the top above the table with the filters. The tall row would show the data from the currently selected row in the table. Your table rows could then probably be less high.
Add a single text box.
Use ALT+click and drag to resize text boxes to fit cell exactly.
Change or view the name of the textbox in the named range area to "TextBoxQuery".
Add code to change the text in the summary row
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Say the tall row is in row 2
If Target.Row <= 2 Then
Exit Sub
End If
Dim i As Integer
For i = 1 To 8
Cells(2, i) = Cells(Target.Row, i)
Next i
End Sub
You could even allow the user to edit the text in the tall row and add a button to save the changes they entered:
A. Add an ACTIVEX button in the summary row labelled "SAVE"
(Then you can edit the vba in the sheets module for the button)
B. Add a cell somewhere that records which row is being displayed in the summary row.
C. When the save button is clicked, write code that copies all the values in row to back to the row recorded.
NOTE that if the user deletes a row in the table or sorts the data in the table the row stored will be wrong. So before copying the data, you might like to check to see whether the row has moved. ie check a KEY value (ie ones that never changes) is the saem in both rows.
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 8
Cells(Cells(1, 1).Value, i) = Cells(2, i)
Next i
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Say the tall row is in row 2
If Target.Row <= 2 Then
Exit Sub
End If
' Cell A1 is used to store which row is displayed
Cells(1, 1) = Target.Row
Dim i As Integer
For i = 1 To 8
Cells(2, i) = Cells(Target.Row, i)
Next i
End Sub
In Excel, rows of Column A is merged and the rows of Column B are not merged, Now i want to write a macro for finding the count of rows of column B that are not blank for a corresponding value present in column A(which is merged).
Appreciate your help.
Some ideas...
'make sure to get the top-most merged cell
Set rng = ActiveSheet.Range("D3").MergeArea.Cells(1)
Set ma = rng.MergeArea
Debug.Print rng.Address(), ma.Address(), _
rng.Offset(0, 4).Resize(ma.Rows.Count, 1).Address()
Debug.Print Application.CountA(rng.Offset(0, 4) _
.Resize(ma.Rows.Count, 1))
To build a macro go to Developer > Record Macro and click OK. Press keys or buttons to suit and when the result is as desired click on Stop Recording.