I would like to add additional fixed text to textbox data in specific cells in an Excel spreadsheet. For example, in the textbox the user would enter "g0/0" but in the cell A2 it should read "interface g0/0". Here is what i have so far:
Private Sub Populate_Click()
Dim ws As Worksheet
Set ws = Worksheets("Remote")
ws.Range("A2") = Interface.Value
So I assume i would add "interface" somewehere on that last line but i am unsure of the syntax.
thanks!
You may need to first sonstrict the required value in a string, then make that the value of "A2". Assuming your input text box is on a form...
Dim InterfaceValue as string
InterfaceValue = "interface" & FormName.InputTextBox.Value
ws.Range("A2").value = InterfaceValue
You can try to loop all the rows, and insert fixed string value to a cell.
Ex.
for(XMLResource report: reports) {
Row row = sheet.createRow(rowNum++);
sheet.setColumnWidth(0, 1000);
row.createCell(0)
.setCellValue(report.getPage());
row.createCell(1)
.setCellValue(report.getTestName());
row.createCell(2)
.setCellValue(report.getDescription());
row.createCell(3)
.setCellValue(report.getSTATUS());
row.createCell(4)
.setCellValue(report.getBuisImpact());
row.createCell(5)
.setCellValue(report.getVali());
}
(report is string only object)
Related
I'm trying to make a excel macro to find a name in a table, let's say I want to find Mark, and want it with an input box, that one I know how to do:
InputBox("Qual o Nome?")
But I would like that there is a list to choice from, instant of having to write the name every time, so lets say the names are in Row C (let's say C4:C15).
After finding the name (imagine the name is in C5) I want it to select next column (in this case D5), and insert on that cell a value, that will ask in a new InputBox.
Right now I'm having some trouble doing the looking for the name and select new column cell according to the name position.
So this is what I got so far:
Private Sub CommandButton1_Click()
'This one i cant figure it out
Dim Range As Variant
Range = InputBox("Qual o Char?") 'Here is where i say the name
Cells(Range, 1).Value = InputBox("Focus actual?") 'Here i want it to insert in the cell right, after the name it looked for
Cells(Range, 2).Value = Now() 'Here i want it to insert in 2 cell right, after the name it looked for
End Sub
Your code will look something like:
Private Sub CommandButton1_Click()
'Declare the variables you will need to store the found range and two user inputs
Dim foundRange as Range
Dim userInput1 as String
Dim userInput2 as String
'get your user input into variables
userInput1 = InputBox("Qual o Char?") 'Here is where i say the name
userInput2 = InputBox("Focus actual?")
'Use the Found method of the Range object to find your userInput
foundRange = Sheet1.Range("A1:Z500").Find(userInput, lookin:=xlValues)
'Use Offset() to move around and place values:
foundRange.Offset(0,1).Value = userInput2 'Here i want it to insert in the cell right, after the name it looked for
foundRange.Offset(0,2).Value = Now()
End Sub
Likely some more work will be needed to validate your user input or do something different if Range.Find() comes up empty, but this should get you in the ballpark.
Basically, I have two excel sheets. What I am trying to do is to copy specific cell value from current cell to another. Let say, I have a form sheet of cash deposits:
Cash deposits form info:
and then, I need to copy and paste some of the data needed to another form.
This is the form where I want to paste the cell value from cash deposits:
I tried Macro but I have a limited knowledge about it and it seems difficult for me. any idea?
Sub move_data()
Dim main_sheet As String
Dim target_sheet As String
Dim info1 As String
Dim target_info1 As String
Dim info2 As String
Dim target_info2 As String
'CONFIG
'--------------------------
main_sheet = "Sheet1" 'set sheet name to copy from
target_sheet = "Sheet2" 'set sheet name to paste in
'cells to copy
info1 = "A1"
info2 = "B1"
'cells to paste
target_info1 = "B1"
target_info2 = "B2"
'----------------------
Sheets(target_sheet).Range(target_info1) = _
Sheets(main_sheet).Range(info1)
Sheets(target_sheet).Range(target_info2) = _
Sheets(main_sheet).Range(info2)
End Sub
If you need to copy/paste more cells, just add more String variables as info1 and info2 with their correspoding target cell to paste in and add the following code before the End Sub making the corresponding changes in the variable names.
Sheets(target_sheet).Range(target_info2) = _
Sheets(main_sheet).Range(info2)
The way to copy the values of one set of cells into another is as follows:
Say you want to copy the range "A2:G101" (100×7 table) from Sheet1 to "F2:L101" (100×7 table) of Sheet2
Sheet2.Range("F2").Resize(100,7).Value = Sheet1.Range("A2").Resize(100,7).Value
In other posts you will see the .Value omitted because it is the default property, but it is not recommended to do so because it hides the intent of the code.
The above works with [named ranges] in the Range() specification as well as "A1" style referencing. The .Resize() command expands the reference from one cell to multiple rows and columns (given as rows, columns).
I want excel to automatically create hyperlinks to another cell. I have one column with different strings and when i type the name of one of the existings strings in another column i want a hyperlink to the cell in the first column automatically. Is this possible and how would you then do it?
if you're using VSTO:
Declare SortedList Object in ThisAddin to keep Keywords and Range Address
Dim keywordList As New SortedList(Of String, String)
In Application.SheetChange can you catch the string you typed.
You can use Target.Value and Target.Address.
Look up for Target.Value in the SortedList. If nothing found add new entry to the list with value and range address.
if entry is already declared get the address from the list and create Hyperlink for Target
Public Sub Application_SheetChange(ByVal Sh As Object, ByVal Target As Microsoft.Office.Interop.Excel.Range) Handles Application.SheetChange
Dim value As String = CStr(Target.Value)
If liste.ContainsKey(value) Then
Dim address As String = String.Empty
keywordList.TryGetValue(value, address)
If Not String.IsNullOrEmpty(address) Then
Target.Parent.Hyperlinks.Add(Target, address)
End If
Else
keywordList.Add(CStr(Target.Value), CStr(Target.Address))
End If
End Sub
Not exactly what you asked for but it could make the job:
Assuming you have a file named "test.xlsx"
In column "A" write your strings
In column "C" write string you want to make hypertext link
In column "D" write =MATCH(C2;A:A;0)
In column "E" write =HYPERLINK("[test.xlsx]A"&D2;"GO TO "&C2)
Points 4 and 5 could by merged into one formula.
The difference between your description and my solution is that I construct hyperlink in adjacent cell (not the cell you write search string into)
I have a drop down in Excel which has a link to a cell depending on a list of values(string format) in another sheet. while changing the drop down i need the value selected (and not the index) as a string in the VBA code for further use.
I have searched and found that it can be shown as a msgbox, but i need it in the VBA code for further use in the code.
how can i get this value.
Thanks
If you have a Forms-type dropdown (not ActiveX), then you could can use the ListFillRange and Value properties to get the value selected. The Value property returns the position in the list and the ListFillRange property is a string representation of the range.
Sub GetListFillRangeSelection()
Dim dd As DropDown
Dim rInput As Range
Dim sSelected As String
Set dd = Sheet1.DropDowns(1)
Set rInput = Range(dd.ListFillRange)
sSelected = rInput.Cells(dd.Value, 1).Value
Debug.Print sSelected
End Sub
I need a code that will delete the enitre row when a specific name is typed into column A.
So, for each row that has "Surgery" in column A, it needs to be deleted. Thanks.
This should work. All you need to do is change the value of areaToSearch to fit your workbook. Also watch the case on the keyword, "Surgery" and "surgery" are not the same! I tested this and it worked on a sheet I made up.
Option Explicit
Sub DeleteSurgery()
Dim keyWord As String
Dim cell As Range, areaToSearch As Range
keyWord = "Surgery"
Set areaToSearch = Sheet1.Range("A1:A10")
For Each cell In areaToSearch
If cell.Value = keyWord Then
cell.EntireRow.Delete
End If
Next cell
End Sub