Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 50112 articles
Browse latest View live

format userform output to email

$
0
0
I have a macro that creates an email based on the values inputted by users in both listboxes and textboxes on a userform. However I want to make the values a certain format, e.g. some text red and other text bold.

what code would i add to enable this?

e.g.
With MyItem
.To = "xxx@xxx.com
.Subject = ListBox7.Value
.Body = ListBox1.Value & vbNewLine & _ <----- want to make this listbox value red
TextBox1.Value & vbNewLine & _ <--- want to make this textbox value bold
"Enjoy your day " <--- want to make this plain text value bold
.display

Gracias!

Using VBA to pre-fill website information

$
0
0
Is it possible to use VBA to enter information into a website page automatically rather than having to enter the same info again and again?

Where would I begin learning this approach...

Anyone have any good links for this topic?

VBA Code to advanced filter or...some other solution (with sample)

$
0
0
Hi guys

Im stuck with something that i don't know if its even possible. First of all this is for excel 2000.
I already have a way do get a record from A3:G41 with two conditions (formula on cell P4). What i need is a way to populate others cells (or another table) if the values in L4 and M4 match with the ones in column C and D. For example i have 300 in L4 and 16 in M4, what i need is a way to show me the values from C4 to H4, C29 to H29 and C30 to H30, the ones that match. I need this because using the conditions in L4 and M4 to get the values that match in the other table, those values will be use for a graph, but i think this will maybe be a little tricky..
Sorry if my explanation is weak :-p

A member as suggest me to use a advanced filter but then i need to make it automatically when i introduce different valuer in L4 and M4, he said that only with VBA code i can automate this operation. I attached the example that he give it to me with the filter and if someone could help me out with a code to automate this i appreciate.

Thanks in advance ;-)
Attached Files

Macro - Moving Cells

$
0
0
How do I move cells from column B over to Column A for all sheets using a macro? After running macro, I need all sheets to look like tab titled "view after macro"
Attached Files

Different possible combination using division formula function within a column

$
0
0
Hi,

I have a question involving using the division formula. Attached is the picture of what I am trying to do.

So basically, C , D, E, F are columns and the right side is what I want to do.

So for person A, I want to do many possible divisions of the cells in that column. So as shown in the picture, the light blue means [All cell]/[first cell], and dark blue means [all cells]/[second cell] and continue on until the last cell in column E. Then from there, it will be inverse division e.g.[first cell]/[all cells], [second cell]/[all cells] and so on. So it is like doing all possible combination of division.

So next column will be the same as the previous column, where you do all possible division in Column F.

The problem here is, I have massive of data (thousands of values and Person ID), so it is impossible to do it manually as I have to keep changing the $ sign and letter, as well as dragging down all the way to the last cell which can be at Row 1000++ . Is there any other way to do it?

I know a bit of VBA and vb.net, so if there is a formula to cater this...I greatly appreciate it!
Attached Images

how to eliminate duplicate url values in rows and sum up the associated column values

$
0
0
I am trying to Find out the common/similar urls, strip down the parameters in the following urls and add the views/visits column values of the common URLs to essentially eliminate duplicate rows (as shown below)...have tried multiple things and yet not able to achieve the desired results..can someone please help me with this?

Thanks

URL - views - visits

Www.abc.com/407.jsp - 32 -9

Www.abc.com/407.jsp#test - 66 -78

Www.abc.com/407.jsp#test-yhg - 77 - 88

Www.abc.com/407.jsp#testtrue - 54 - 99

Www.abc.com/401.jsp - 67 - 21

VBA paste in different column each time

$
0
0
I have the below VBA code, it copies a range and pastes it as values of a different sheet, is it possible with each copy that is pasted moves to the next blank column each time?

for example if I ran the vba for the first time it would paste the data in A10 but the second time it would paste it in B10 and so on.


Sub CopyPaste()
Dim ws As Worksheet
For Each ws In Worksheets

If ws.Name <> "Sheet1" Then

ws.Application.Run "Macro1"
End If
Next
End Sub

Sub Macro1()
Range("A2:A13").Copy
Sheets("sheet2").Range("A10").PasteSpecial xlValues
End Sub

[SOLVED] For control variable in use (simple macro in add-in)

$
0
0
Hi All, I got this SplitSheets macro to work as a button but when I used it in an add-in it stopped working. From internet research I know I can not refer to the same variable in my second "For" statement but when I try to define the active sheet twice I don't get my desired result of splitting my workbook into separate files by tab. The problem is located in the line of the second "For" statement:

Code:

Sub Splitbook()
Dim Mypath As String
Dim sht As Worksheet
Mypath = ThisWorkbook.Path
For Each sht In ThisWorkbook.Sheets
sht.Copy
ActiveSheet.Cells.Copy
ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Cells.PasteSpecial Paste:=xlPasteFormats
For Each sht In ActiveWorkbook.Worksheets
        sht.Unprotect Password:="gordon"
        sht.Protect Password:="gordon"
Next
ActiveWorkbook.SaveAs _
Filename:=Mypath & "\" & sht.Name & ".xlsx"
ActiveWorkbook.Close savechanges:=False
Next sht
End Sub


Hide rows

$
0
0
Hi I want to make hide rows in a way that if I type "HD" and "HDE" in another cell in column A, it should hide all rows starting from Cell "HD" to "HDE"

Eg. If I typr "HD" on A3 and "HDE" on A15, excel should hide A3:A15.


Any help is much appriciated.

Thanks :)

Issue with converting excel to word and then mailing it using outlook

$
0
0
I have this code for converting excel to word but i need to mail it once the data is copied to wordpad.

Please help

Sub CopyToWord()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim i As Integer

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add ' create a new document
wrdApp.Visible = True
start_row = 1
end_row = 1

For i = 1 To 1000
If Cells(i, 1).Value = "First" Then
start_row = i
End If
If Cells(i, 1).Value = "Last" Then
end_row = i
End If

Next i

'copy As Picture
Range("B" & start_row & ":M" & end_row).CopyPicture xlScreen, xlPicture
wrdDoc.Range.Pasteandformat 0

'Copy as HTML
'Range("B" & start_row & ":M" & end_row).Select
'Selection.Copy
'wd.Range.PasteExcelTable False, False, False

'Copy as Rich Text
'Range("B" & start_row & ":M" & end_row).Select
'Selection.Copy
'Cells(2, 2).Select
'wrdDoc.Range.PasteExcelTable False, False, True


' wrdApp.Quit ' close the Word application

Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub

Question about Copying and Pasting When The Range Varies

$
0
0
Hi,

I have a macro that calculates the mean and standard deviation of a given data range to + and - 3 degrees. The problem Im having is that the data ranges I am using vary in length. for example:

Code:

var_mean = Application.WorksheetFunction.Average(wkst.Range("B2:B15"))
 
  Worksheets("Sheet2").Range("F2:F15").Value = var_mean

This works great when the range length im pulling from is the same as whats specified above, but sometimes that specified length of range is different. Mean is calculated based on the data in the range "B2:B15" and then is placed in the range "F2:F15". As I said previously, this works when the data range is that length, but it doesnt work so great when the range is a different size. How do I tell the program to start at "B2"(always at the 2nd row level) and use all the cells in the column(range) until you get to the end of the used range of numeric values, then paste starting at "F2" and go until the end of the used range?

[SOLVED] Find latest date when the name appeared either formula or vba multiple sheets

$
0
0
Hi,

I have 3 sheets in a work book.
In column A, I enter the date in each sheet
In Column G, I enter the name in each sheet

I want to populate in 3rd sheet with latest date when the name had appeared.
It is very tiring to type Lookup or Vlookup in each cell .( actual workbook there is too much of a data)
Is there any easy way of doing it please?
I have attached sample workbook
Many thanks
Kind regards:)
Attached Files

EXCEL 2013 - opening read only files and editing them

$
0
0
Hi All,

Hoping to find some help with a problem I've been having. My work just upgraded to office 2013 and a few macros I created are not working anymore.

I have a macro that opens a word document and populates it with information from the excel workbook. I have it so that the word document opens as read-only. Part of the code looks like this:

Set wdDoc = wdApp.Documents.Open("U:\Data\Letterhead.docx", ReadOnly:=True)

However, I get the run-time error '6124': You are not allowed to edit this selection because it is protected.

If I change the code so that it doesn't open as read only, then it will work just fine. But I want to make sure the word document is kept as a read only file as it is a template. I don't want someone to accidentally save over the master template.

The macro/code worked how i wanted it to in prior versions of excel, but wont work in excel 2013. Any ideas on why that is?

Thanks...

Create CSV file with quotes " " around each field

$
0
0
I am attempting to create a CSV file and need to place quotes around each cell in a defined range.

Refresh all queries on workbook open, when finished print to pdf then close workbook

$
0
0
I have data that daily needs to be refreshed and printed to pdf.

I figure the simplest way to do this would be to task schedule the workbook to open daily.
Then on open it will refresh the data, print it after all data has been refreshed and close the workbook.

I set it up originally without the need to print so I have all the queries set to refresh when opening the file, however when I now try and put the code to print to pdf on the workbook open event it runs before the queries are finished running.
(Query notes:
queries were created through Microsoft query, and are accessing a MySQL database
queries set to refresh when opening the file
queries set to enable background refresh).

I am very new to scripting so if anybody could provide simple step by step instructions on how I could do this it would be greatly appreciated :)

Find value of a cell in another worksheet. Use offset formula to change adjacent cell.

$
0
0
I have been racking my brain trying to figure this out. It worked before and now i get a run time error '91'. "Object variable or with block variable not set"
What am I doing wrong?

Objective:

I want to find the value of one cell in another worksheet.
once that value is found on that sheet I want to change the value of the adjacent cell to another value.

I can't get past the "Find code"

Code:

Dim acell as range
set acell=sheets("Screening Questionaire").range("H12")

ActiveWorkbook.Sheets("Candidate Pipeline").Activate
  Cells.Find(What:=acell.Text, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate

activecell.offset(0,1).select
activecell.value=Range("submit")

[HELP] How to Make Navigation GUI

$
0
0
Hi There,

Its me again seeking for help, and want to learn more about excel.

I am created Financial Worksheets. . . ex. Balance Sheet, Income Statement, Cash Flows, Notes, Forecasted Sales Etc.
and I want to make a GUI in-order to navigate easily. I already included Hyper Links to it for some detailed annexes.

Please Help me with this.

Thank You.

How can i find all duplicates in 3 columns and clear contents in all but first column A

$
0
0
I use conditional formatting in my code to find duplicates. I need to be able to clear all cells that are found except the ones in Column A.
Ive read on forums that it is very difficult to clear cells based on conditional formatting. How would I rewrite the code so I doesn't use conditional formats that way I could try to clear the cells also? Currently im using this...
Code:

WS.Range("B3:f500").Select
    Selection.FormatConditions.AddUniqueValues
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).DupeUnique = xlDuplicate
    Selection.FormatConditions(1).Interior.ColorIndex = 6
       
    Selection.FormatConditions(1).StopIfTrue = False

Any input or links to relevant posts would be appreciated.
Thank you in advance.

Converting a pictures description to the cell

$
0
0
Hi,

I am using 2013 and I have a very large spreadsheet with 40,000 cells that each have a picture of a star rating in them. If you look at the pictures description by right clicking on it, it says "4 Star, 5 Star..." or whatever it is.If there is a way to make it so that the cells can be populated by the picture in the same cell's description, then please let me know. Or if there is a way to macro this problem or any possible ways to reduce the time rather than going through all 40,000 cells.

Thanks for helping,

Mitchell

VB Code to Save file as 97-2003 Worksheet

$
0
0
Hello:

Please refer to attached sheet.
I am using below code to rearrange the Clockin-Clockout of employees.
I need to add the code which will Save and close the file in Microsoft Excel 97-2003 Worksheet in the same location as the original after rearranging is done.
Please let me know if any questions.
Thanks
Riz

Code:

Sub TimeReport_CSR()
' THIS MACRO IS CONTROL+SHIFT+R
  Dim C As Long
  Dim n As Long
  Dim r As Long
  Dim Rn As Long
  Dim TimeIn As Long
  Dim TimeOut As Long
  Dim Wks1 As Worksheet
  Dim Wks2 As Worksheet
 
 'Wks1 = the original data sheet
  With ActiveWorkbook
    Set Wks1 = .Worksheets(Worksheets.Count)
    .Worksheets.Add After:=Worksheets(.Worksheets.Count)
    Set Wks2 = ActiveSheet
    Wks1.Activate
  End With
 
  Rn = 2
  n = 2
 
 'Count the Rows with IDs
  Do
    If Wks1.Cells(n, "A").Value = 0 Then Exit Do
      n = n + 1
  Loop
 
 'Quit if there are no IDs
  If n = 2 Then Exit Sub
 
 'Set the header row for Sheet2
  With Wks2
    .Cells(1, 1).Value = "ID_CODE"
    .Cells(1, 2).Value = "IN"
    .Cells(1, 3).Value = "OUT"
  End With
 
 'Copy desired data to Sheet2
  For r = 2 To n - 1
    IdCode = Wks1.Cells(r, "A").Value
      For C = 5 To 14 Step 3
        TimeIn = Wks1.Cells(r, C).Value
        TimeOut = Wks1.Cells(r, C + 1).Value
          If TimeIn = -1 Or TimeOut = -1 Then Exit For
        With Wks2
          .Cells(Rn, "A") = IdCode
          .Cells(Rn, "B") = TimeIn
          .Cells(Rn, "C") = TimeOut
        End With
        Rn = Rn + 1
      Next C
  Next r
 
  'Sort list in ascending order by ID
 With Wks2
  .Range("A2:C" & Trim(str(Rn))).Sort Key1:=.Range("A2")
  End With

 
'Save the original data worksheet name
  TabName = Wks1.Name
 
'Delete the worksheet
  Application.DisplayAlerts = False
  Wks1.Delete
  Application.DisplayAlerts = True
 
'Rename the new sheet
  Wks2.Name = TabName
 
End Sub

Attached Files
Viewing all 50112 articles
Browse latest View live