アプリ版:「スタンプのみでお礼する」機能のリリースについて

VBA処理追加
こちらでご教示頂いたのですが回答完了させてしまいましたのでこちらからまた質問させてください。
前回回答いただいた方追加で申し訳ないのですが
上の画像(元データ)の黄色のセルの文字を下の画像(結果)のように名前に関連させて表示させたいのですがどうすればよろしいでしょうか?
ご教示お願い致します。

Option Explicit

Public Sub ユークリッド距離順()
Const BA1 As Long = 1000 '表縦の倍率
Const BA2 As Long = 100 '表横の倍率
Const BA3 As Long = 10 '表高の倍率
Const BA4 As Long = 1000 '裏縦の倍率
Const BA5 As Long = 100 '裏横の倍率
Const BA6 As Long = 10 '裏高の倍率
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim dicT As Object
Dim maxrow1 As Long
Dim namerow As Long
Dim wrow As Long
Dim row2 As Long
Dim name As String

Dim d1 As Long, d2 As Long, d11 As Long, d12 As Long, d13 As Long, d21 As Long, d22 As Long, d23 As Long
Set dicT = CreateObject("Scripting.Dictionary") ' 連想配列の定義
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
maxrow1 = sh1.Cells(Rows.Count, 1).End(xlUp).Row '
If name = "" Then Exit Sub
sh2.Rows("5:" & Rows.Count).ClearContents '5行目以降クリア
namerow = 0
For wrow = 3 To maxrow1
If name = sh1.Cells(wrow, 1).Value Then
namerow = wrow
End If
Next
If namerow = 0 Then
MsgBox (name & "が存在しません")
Exit Sub
End If
'ユークリッド距離の計算
row2 = 5
For wrow = 3 To maxrow1
If wrow <> namerow Then
sh2.Cells(row2, 1).Value = sh1.Cells(wrow, 1).Value '表名前
sh2.Cells(row2, 4).Value = sh1.Cells(wrow, 1).Value '裏名前
d11 = (sh1.Cells(wrow, 2).Value - sh1.Cells(namerow, 2).Value)
d12 = (sh1.Cells(wrow, 3).Value - sh1.Cells(namerow, 3).Value)
d13 = (sh1.Cells(wrow, 4).Value - sh1.Cells(namerow, 4).Value)
d21 = (sh1.Cells(wrow, 5).Value - sh1.Cells(namerow, 5).Value)
d22 = (sh1.Cells(wrow, 6).Value - sh1.Cells(namerow, 6).Value)
d23 = (sh1.Cells(wrow, 7).Value - sh1.Cells(namerow, 7).Value)
d1 = d11 * d11 * BA1 + d12 * d12 * BA2 + d13 * d13 * BA3
d2 = d21 * d21 * BA4 + d22 * d22 * BA5 + d23 * d23 * BA6
sh2.Cells(row2, 2).Value = d1 '表距離
sh2.Cells(row2, 5).Value = d2 '裏距離
row2 = row2 + 1
End If
Next
'ソート
sh2.Range("A5:B" & row2 - 1).Sort key1:=sh2.Range("B5"), Order1:=xlAscending, Header:=xlNo
sh2.Range("D5:E" & row2 - 1).Sort key1:=sh2.Range("E5"), Order1:=xlAscending, Header:=xlNo
sh2.Rows("10:" & Rows.Count).ClearContents '10行目以降クリア
MsgBox ("完了")
End Sub

「VBA処理追加 こちらでご教示頂いたので」の質問画像

質問者からの補足コメント

  • 追加で申し訳ございません。
    値が入っている所に"ー"(ハイフン)などの特定の物を削除してから計算させたいときはどうしたらよろしいでしょうか?よろしくお願い致します。

      補足日時:2022/10/27 11:10

A 回答 (2件)

下記にアップしました。


https://ideone.com/yU0FQ1
    • good
    • 0
この回答へのお礼

ありがとうございます。確認出来ました。
また、質問するかも知れませんがよろしくお願い致します。

お礼日時:2022/10/27 10:41

>追加で申し訳ございません。


つぎつぎと、仕様の追加が入ってくると、きりがありません。
もし、ほかにも追加があるのなら、そのついかも含めて、質問を追記してください。


>値が入っている所に"ー"(ハイフン)などの特定の物を削除してから計算させたいときはどうしたらよろしいでしょうか?よろしくお願い致します。

ハイフンを取り除いてから計算ということになります。
どのようにハイフン等が入っているのかが判りません。
ハイフン等の入っている例(すべての例をあげてください。)と
それをとりのぞいた結果を提示してください。
    • good
    • 5
この回答へのお礼

申し訳ございませんでした。
他にもないか確認して質問致します。

お礼日時:2022/10/27 11:37

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!