Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm a beginner in VBA, I've been searching in the internet that could possibly help me get any ideas about my problem.But I can't find any result that is closely related to what I've been searching for, so I came here. I can't wrote any macro about this because I don't even know where to start.I have an excel as my database containing an ID number and a last name of a person. I want to create a macro that has an input box.If the value/text is found anywhere in the workbook the cell is highlighted in yellow. Any suggestions will be appreciated.
Thanks in advance.
If you can do without the input box and just enter your search text into a cell instead, I have a solution that involves no macros.
Just use conditional formatting instead. If the first cell of your data was say B2, highlight that cell and select conditional formatting from the ribbon menu, then New Rule followed by Use formula. In the format values enter the following:
=NOT(ISERROR(FIND($D$1,B2,1)))
Where B2 is you highlighted data cell and $D$1 is the cell where you are entering your search text. You can change the search cell location but must have the $$s.
Next hit the format button and change the fill color to yellow, then click OK.
All you then need to do is copy the format from the first data cell to the rest of the column.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Working on a vendor's sales document provided by a grocer, which lists the number of units they sold. Issue is that their excel sheet and the way they record sales (which I cannot change) doesn't differentiate between single bars sold and boxes sold - so some rows state "Mint Bar" = 1 sold and some state "Mint Bar Box" = 1 sold. The unit values are the same in the sheet, but the "box" should really = 12 (since a box is 12 units, not just 1).
The second issue is that every time "box" appears that value needs to be n*12 (so 1box*12 = 12 bars).
Thus, I am looking for some code to help me out. I know this is easy in SQL and have less experience running excel macros.
--
Fixed:
Where the Boxes appear in D2, D6, D8, etc:
=if(Cell="Box", 12*D2, 12*D6, 12*D8)
Drag formula down for all the rows in the sheet.
do you have to do this in a macro? I would just add another column that says
=if(Cell="Mint Bar Box", 12, 1)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Files here
Hello,
I am trying to write code to format a report. The main issue with the report is that some cells store multiple pieces of data in a cell when each row should only have one piece of data in each cell. My solution thus far has been to use the text to columns function for the affected cells, paste all other data transposed, and finally copy and re-transpose the new data over the original report area. This has worked so far, but I am running into an issue with cells that store time. Cells with single times (such as 13:00) are in the custom format hh:mm, which vba converts to a a decimal number. Cells with multiple times (such as 11:009:008:0010:30) are viewed as a string.
The code I am currently using to split the times works for multiple time cells because it searches the string for ":", but vba does not detect the ":" in the custom format cell 13:00 since internally it sees that cells value as something like 0.56412.
I am kind of at a loss as to what to do here. I can't change the format that the report arrive to me in. My thought was that maybe I could find a way to turn the custom format "13:00" into a string "13:00" instead of 0.56412
I have attached the code file and the truncated dummy report I am testing to code on. I would like to thank everyone who responds for their help in advance!
to change a single time to a string, you can use format and identify the value to excel as a string using '
example:
'immediate window
[a1]="'"&format([a1],"hh:nn")
'or, using a range
range("A1")="'"&format(range("A1"),"hh:nn")
you can use isnumeric to check if it's a single time. True means it's a time, False means it's a string of times
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to copy the data from one worksheet and paste it in another worksheet. But it is not working and asking me to use "A1" or R1C1. But I need to start the pasting from cell A5.
This is the code -
Range("A5:C9").PasteSpecial
Kindly share your thoughts. Thanks.
If you just need to paste the data from one worksheet to another, you can skip PasteSpecial (well, .Copy altogether) and just set the two ranges equal to another.
Worksheets("DESTworksheet").Range([DESTINATION range]).Value = Worksheets("ORIGINworksheet").Range([COPY range]).Value
So, try:
Worksheets("DestinationSheet").Range("A5:C9").Value = Worksheets("CopyFromSheet").Range("A5:C9").Value
Of course changing the worksheet names (and/or ranges) as necessary.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Need help in using vba to auto filter columns in a workbook but the filter criteria is in a cell reference on another workbook. To Start, i have 2 workbooks, the first is the report template where the macro is entered and the other is the data file that needs to be filtered.
You can reference reference cells in the (closed) template workbook in your Autofilter VBA statement. ExecuteExcel4Macro is of help here, permitting to evaluate a reference to another, closed workbook the same way it would be typed in a formula.
For example, to autofilter a range by cell B5 of the control sheet in the report template:
myRange.AutoFilter 1, ExecuteExcel4Macro("'C:\myPath\myfolder\[Report.xltx]control'!R5C2")
Notice that ExecuteExcel4Macro requires RC-style addresses, so use R5C2 for B5, R5C3 for C5 and R5C4 for D5...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Here's the situation:
I have two excel sheets.
The first sheet contains a table of product codes and product descriptions (Two columns A and B).
I have a second sheet where someone is supposed to enter the product code and automatically have the next cell fill up with the product description and the cell next to it with the time.
I was wondering if that's do-able without VBA? If so, can someone give me start.
Best,
You could have the first cell that you want to auto fill have an IF statement, where if the cell has no value, nothing happens, and anything other than that gets a calculation.
Using A2:B100 as a Range if you have a header Row. Adjust to your own needs, of course.
IF FUNCTION
'IF (condition, result if true, result if false)'
VLOOKUP FUNCTION
'VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)'
=If($A1 = "", "", VLOOKUP(A1,Sheet1!$A$2:$B$100,2))
The next cell over would have something similar:
=IF($A1 = "", "", NOW())
This will get you the time. You will also have to have the cell format set to Time.
There is a problem with that. The screenshot below illustrates it.
It will just keep refreshing with the current time over and over. I would use a bit of VBA to solve that by setting the value property instead of a formula.
Sheets("Sheet2").Cells(row,col).Value = Now()
You could copy and paste the value into another cell. Just the value. Not the formula.
Or you could check out this article: about generating Time Stamps.
edit: included VBA solution